You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Charles Honton (JIRA)" <ji...@apache.org> on 2015/08/26 04:25:46 UTC
[jira] [Commented] (LANG-1166) FastDateFormat does not honour 'ZZ'
pattern
[ https://issues.apache.org/jira/browse/LANG-1166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14712373#comment-14712373 ]
Charles Honton commented on LANG-1166:
--------------------------------------
FastDatePrinter javadoc explicitly states:
{code}
Java 1.4 introduced a new pattern letter, {@code 'Z'}, to represent
time zones in RFC822 format (eg. {@code +0800} or {@code -1100}).
This pattern letter can be used here (on all JDK versions).
In addition, the pattern {@code 'ZZ'} has been made to represent
ISO 8601 full format time zones (eg. {@code +08:00} or {@code -11:00}).
This introduces a minor incompatibility with Java 1.4, but at a gain of
useful functionality.
Starting with JDK7, ISO 8601 support was added using the pattern {@code 'X'}.
To maintain compatibility, {@code 'ZZ'} will continue to be supported, but using
one of the {@code 'X'} formats is recommended.
{code}
The SimpleDateFormat javadoc states:
{code}
RFC 822 time zone: For formatting, the RFC 822 4-digit time zone format is used:
RFC822TimeZone:
Sign TwoDigitHours Minutes
TwoDigitHours:
Digit Digit
{code}
SimpleDateFormat will output +0000 whether 'Z', 'ZZ', 'ZZZ', or 'ZZZZ' or however many 'Z' are used.
FastDateFormat will output +0000 for 'Z' and Z (ISO8601) for 'ZZ'
It's not just UTC that has the formatting difference. In Paris, FastDateFormat will output +02:00 instead of +0200; and in Los Angeles, -07:00 instead of -0700.
So, for compatible with SimpleDateFormat use 'Z'.
> FastDateFormat does not honour 'ZZ' pattern
> -------------------------------------------
>
> Key: LANG-1166
> URL: https://issues.apache.org/jira/browse/LANG-1166
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.time.*
> Affects Versions: 3.4
> Reporter: Abhishek Gupta
> Fix For: 3.5
>
>
> A date format of "yyyy-MM-dd'T'HH:mm:ss.SSS ZZ" returns "2015-08-13T11:37:13.203 Z" for UTC timezone in version 3.4.
> Same format with version 3.3.2 returns "2015-08-13T11:39:28.452 +00:00"
> The code which i am using to test this is as follows:
> {code:java}
> import org.apache.commons.lang3.time.FastDateFormat;
> import java.util.Date;
> import java.util.TimeZone;
> public class FastDateFormatTest {
> private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS ZZ";
> private static FastDateFormat fastDateFormat = FastDateFormat.getInstance(DATE_FORMAT, TimeZone.getTimeZone("UTC"));
> public static void main(String[] args) {
> System.out.println("fastDateFormat = " + fastDateFormat.format(new Date()));
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)