Java SimpleDateFormat: Difference between revisions
Jump to navigation
Jump to search
Line 50: | Line 50: | ||
=DateFormat and Timezone= | =DateFormat and Timezone= | ||
[[java DateFormat | <blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;"> | ||
:[[java DateFormat Timezone]] | |||
</blockquote> | |||
=Time Zone= | =Time Zone= |
Revision as of 01:09, 13 July 2016
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 DateFormat Timezone.
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
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".
DateFormat and Timezone
Time Zone
Z
for -0800
Just one single "Z" not four or five.
UTC
Use Time Zone (see above) and "0000".
Examples:
This is UTC.
15/01/01 01:01:01+0000
This is PDT.
15/01/01 01:01:01-0700
Z in Time Stamp
"Z" means GMT in ISO 8601
To parse that, add "X" in the pattern.
Various Examples
"2015-09-22T18:03:46Z" is parsed by "yyyy-MM-dd'T'HH:mm:ssX"