| Author |
IMPORTANT! Wrong week of year in GregorianCalendar
|
Jeppe Sommer
Ranch Hand
Joined: Jan 07, 2004
Posts: 263
|
|
Hi, I have a method which return the WEEK_OF_YEAR. On my local server it works fine, but on the host server it fails after the 25. of December 2004. It seems that week 53 is missing (se documentation below!). Code: /* * @input * String timestamp (yyyy-mm-dd) * @output * int week of year */ public int getWeek_In_Year( String timestamp ){ java.util.GregorianCalendar gcl = new java.util.GregorianCalendar( Integer.parseInt( timestamp.substring(0,4) ), Integer.parseInt( timestamp.substring( 5, 7 ) )-1, Integer.parseInt( timestamp.substring( 8, 10 ) ) ); int week = gcl.get( java.util.GregorianCalendar.WEEK_OF_YEAR ); return week; } Output documentation: Data output on the host server: Browser output: 2005, week 2 Input String: 03-01-2005 (week 1) Browser output: 2005, week 1 Input String: 01-01-05 (week 53) Browser output: 2004, week 1 Input String: 31-12-2004 (week 53) Input String: 27-12-2004 (week 53) Input String: 26-12-2004 (week 52) Browser output: 2004, week 52 Input String: 25-12-2004 (week 52) Can anyone help, please! Regards Jeppe (Denmark)
|
 |
Jeppe Sommer
Ranch Hand
Joined: Jan 07, 2004
Posts: 263
|
|
Problem solved with: java.util.GregorianCalendar cal = new java.util.GregorianCalendar( new Locale("da") );
|
 |
Joel McNary
Bartender
Joined: Aug 20, 2001
Posts: 1815
|
|
Hi, Jeppe: I see you've been around for about a year here on the Ranch, but as you haven't posted very much, it seems that no one has pointed you to our Naming Policy. While the number one rule on the Ranch is to "Be Nice," the Naming Policy ranks pretty high up there. Please change your display name to comply (We are looking for a first and last name...) Thanks!
|
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
|
 |
 |
|
|
subject: IMPORTANT! Wrong week of year in GregorianCalendar
|
|
|