Java SimpleDateFormat: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 10: Line 10:
=Overview=
=Overview=


<tt>DateFormat.parse()</tt> returns a <tt>Date</tt> instance whose <tt>getTime()</tt> is always relative to GMT, regardless of the default JVM timezone or the timezone offset specified in the date string. For more details on <tt>DateFormat.parse()</tt> and timezone, see [[java DateFormat Timezone]].
<tt>DateFormat.parse()</tt> returns a <tt>Date</tt> instance whose <tt>getTime()</tt> is always relative to GMT, regardless of the default JVM timezone or the timezone offset specified in the date string. For more details on <tt>DateFormat.parse()</tt> and timezone, see [[Java_Time#Time_Zone_and_DateFormat|Java Time - Time Zone and DateFormat]].


=Samples=
=Samples=

Revision as of 00:20, 7 November 2018

External

Internal

Overview

DateFormat.parse() returns a Date instance whose getTime() is always relative to GMT, regardless of the default JVM timezone or the timezone offset specified in the date string. For more details on DateFormat.parse() and timezone, see Java Time - Time Zone and DateFormat.

Samples

"yy/MM/dd hh:mm:ss,SSS a"

produces:

13/01/31 01:00:00,000 PM

Excel, CSV and milliseconds

Excel understands "." so you may want to:

13/01/31 01:00:00.000 

More here: https://home.feodorov.com:9443/wiki/Wiki.jsp?page=ExcelTimeAndDateFunctions#section-ExcelTimeAndDateFunctions-HandlingMillisecondsInExcel

Hour in Day

Warning If not using AM/PM (no "a" in the format), make sure you use HH for hours (instead of hh).

According to the documentation:

  • "h" - Hour in am/pm (1-12)
  • "H" - Hour in a day (0-23)

Month

To parse "Sep" use "MMM".

To parse "09" use "MM".

"T" in timestamp

If "T" shows in the timestamp, it can be specified as 'T' in format.

Example: "2016-08-03T13:54:39.464-0400" is parsed with:

new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSZ");

DateFormat and Timezone

java DateFormat Timezone