Well, the title says it all. What would be reliable way to determine the current calendar week offset starting from 01.01.1970 UTC using only java.util.Date
?
I am using GWT and therefore I cannot use joda-time oder Calendar
.
Well, the title says it all. What would be reliable way to determine the current calendar week offset starting from 01.01.1970 UTC using only java.util.Date
?
I am using GWT and therefore I cannot use joda-time oder Calendar
.
Jan-01-1970 is Thu, Jan-01-1970 is Sun. Suppose that from Jan, 01 to 04 is week 0.
int oneDaySeconds = 24 * 3600 * 1000;
long offset = new Date().getTime() + 4 * oneDaySeconds; // assume that Monday is first day of week
System.out.println(offset / (7 * oneDaySeconds));
This function has a problem, it's the first day of a week. When use Calendar, denpend on Locale, the first day of week can be Sunday or Monday. If the first day of week is Sunday, the 2nd line should be plus 3 days instead of 4 days