This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes IMPORTANT! Wrong week of year in GregorianCalendar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "IMPORTANT! Wrong week of year in GregorianCalendar" Watch "IMPORTANT! Wrong week of year in GregorianCalendar" New topic
Author

IMPORTANT! Wrong week of year in GregorianCalendar

Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
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: 270
Problem solved with:
java.util.GregorianCalendar cal = new java.util.GregorianCalendar( new Locale("da") );
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

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.
 
Don't get me started about those stupid light bulbs.
 
subject: IMPORTANT! Wrong week of year in GregorianCalendar
 
Similar Threads
getting the start date for a week number
How to display date in Daylight Savings
Threads 001
java.lang.NumberFormatException: For input string: ""
Months and years