Java SimpleDateFormat: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * java Format")
 
No edit summary
Line 1: Line 1:
=External=
* http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
=Internal=
=Internal=


* [[java Format#Subjects|java Format]]
* [[java Format#Subjects|java Format]]
=Samples=
<pre>
"yy/MM/dd hh:mm:ss,SSS a"
</pre>
produces
<pre>
13/01/31 01:00:00,000 PM
</pre>
=Excel, CSV and milliseconds=
Excel understands "." so you may want to:
<pre>
13/01/31 01:00:00.000
</pre>
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)
=Time Zone=
<pre>
Z
</pre>
for -0800
Just one single "Z" not four or five.
=UTC=
Use [time zone|java SimpleDateFormat#Time_Zone] (see above) and "0000".
Examples:
This is UTC.
<pre>
15/01/01 01:01:01+0000
</pre>
This is PDT.
<pre>
15/01/01 01:01:01-0700
</pre>
=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"

Revision as of 17:49, 22 January 2016

External

Internal


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)

Time Zone

Z

for -0800

Just one single "Z" not four or five.

UTC

Use [time zone|java SimpleDateFormat#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"