Created
December 29, 2014 17:30
-
-
Save gigamonkey/75420e4e7c1dc0cc1849 to your computer and use it in GitHub Desktop.
YYYY vs yyyy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.SimpleDateFormat; | |
import java.util.Calendar; | |
import java.util.Date; | |
import java.util.TimeZone; | |
import java.util.GregorianCalendar; | |
public class Foo { | |
public static void main(String[] argv) { | |
TimeZone utc = TimeZone.getTimeZone("UTC"); | |
SimpleDateFormat cy = new SimpleDateFormat("yyyy"); | |
cy.setTimeZone(utc); | |
SimpleDateFormat wy = new SimpleDateFormat("YYYY"); | |
wy.setTimeZone(utc); | |
Calendar calendar = new GregorianCalendar(); | |
calendar.setTimeZone(utc); | |
calendar.set(2010, 0, 1); | |
Date d = calendar.getTime(); | |
String cal = cy.format(d); | |
String week = wy.format(d); | |
System.out.println(d + " Calendar year: " + cal + "; Week year: " + week); | |
} | |
} |
Author
gigamonkey
commented
Dec 29, 2014
FWIW, POSIX date doesn't seem to have that problem. At least, on an ubuntu 14.04 system running in UTC timezone.
$ date -d '2010-01-01' -u +'%G-W%V-%u'
2009-W53-5
Also apparently fixed in newer versions of Java 7 than I have.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment