Using Java’s Calendar or something else, let’s say I set the date to 2012-10-26. I want this date to be the first day of a year. Is it possible to get the week number of a specific date -let’s say it’s 2012-12-10- assuming that the first week of the year starts from 2012-10-26?
I know my question sounds a little weird, but I could use any useful input.
Thanks.
–Details
I have a database table called WeeklySchedule. In this table I have columns starting from Week1 to Week52, and every column have some data about the days of that week. Unfortunately, Week1 is not really the first week of the year. I need to do my calculations assuming that Week1 starts from 2012-08-26.
Here’s one approach using the Calendar API:
Or you could get the diff (in millis) between two calendars and divide the result by the number of millis in a week:
If you use this approach, don’t forget to take TimeZones and Daylight Saving Time into account.
I can’t remember exactly what the code looks like to compensate for DST, but I think it’s something like this:
(I can’t quite remember if you add the offset to or subtract the offset from the two operands)