Search code examples
javagwttime

How to get week of year figure in GWT


Is there a simple way how to get week of year information from a Date object or from millis time in GWT on the client side?


Solution

  • Something like this:

    Date date = new Date();
    Date yearStart = new Date(date.getYear(), 0, 0);
    
    int week = (int) (date.getTime() - yearStart.getTime())/(7 * 24 * 60 * 60 * 1000);
    

    Note that this will give you a week in a Date object, which has no time zone information. When you use it, you may have to adjust it using the time zone information.