[threeten-dev] DateTimeFormatters - pattern Z and X and SimpleDateFormat

yoshito_umaoka at us.ibm.com yoshito_umaoka at us.ibm.com
Tue Dec 18 21:42:45 PST 2012


http://cr.openjdk.java.net/~rriggs/threeten-javadoc/javax/time/format/DateTimeFormatters.html

In this doc, pattern 'Z' and 'X' are defined as:

----
   Z       zone-offset                 offset-Z          +0000; -0800; 
-08:00;
   X       zone-offset 'Z' for zero    offset-X          Z; -0800; -08:00;

 Offset X: This formats the offset using 'Z' when the offset is zero. One 
letter outputs just the hour', such as '+01' Two letters outputs the hour 
and minute, without a colon, such as '+0130'. Three letters outputs the 
hour and minute, with a colon, such as '+01:30'. Four letters outputs the 
hour and minute and optional second, without a colon, such as '+013015'. 
Five letters outputs the hour and minute and optional second, with a 
colon, such as '+01:30:15'.

 Offset Z: This formats the offset using '+0000' or '+00:00' when the 
offset is zero. One or two letters outputs the hour and minute, without a 
colon, such as '+0130'. Three letters outputs the hour and minute, with a 
colon, such as '+01:30'.
----

The doc also mentions that:
----
The pattern string is similar, but not identical, to SimpleDateFormat. 
Pattern letters 'E' and 'u' are merged, which changes the meaning of "E" 
and "EE" to be numeric. Pattern letters 'Z' and 'X' are extended. ...
----

I have some comments:

- Why don't you add "XXXX" and "XXXXX" example cases?  i.e. "Z; -0800; 
-08:00;" -> "Z; -0800; -08:00;+013015;+01:30:15"
- Pattern 'Z' and 'X' are extended. Can we simply extend the definition of 
SimpleDateFormat to support them? Of course, it will be an incompatible 
change, but the impact would be pretty minor.
- Why don't you introduce optional second support to pattern Z? (By doing 
so, only the difference between Z and X is formatting offset zero; "+0000" 
vs "Z").


-Yoshito


More information about the threeten-dev mailing list