If you need the ISO week this is what I'm using in GWT:

    private static final int ISO_THURSDAY = 4;
    private static final int MAX_DAY_OF_WEEK = 6;
    private static final int DAYS_IN_WEEK = 7;
    private static final long MILLIS_DAY = 86400000;

    @SuppressWarnings("deprecation")
    public int getWeek() {
        // http://en.wikipedia.org/wiki/Talk:ISO_week_date#Algorithms
        final Date date = toDate();

        // ISO week day (Mon=1 to Sun=7)
        final int dayOfWeek = 1 + (date.getDay() + MAX_DAY_OF_WEEK) %
DAYS_IN_WEEK;
        final Date nearestThu = addDays(date, ISO_THURSDAY - dayOfWeek);
        final int year = nearestThu.getYear();
        final Date jan1 = new Date(year, 0, 1);
        return 1 + dayDiff(nearestThu, jan1) / DAYS_IN_WEEK;
    }

    public static Date addDays(final Date sourceDate, final long days) {
        return new Date(sourceDate.getTime() + (days * MILLIS_DAY));
    }

    public static int dayDiff(final Date firstDate, final Date secondDate) {
        return (int) ((firstDate.getTime() - secondDate.getTime()) /
MILLIS_DAY);
    }

On Thu, Aug 5, 2010 at 17:15, Glimpse <frederic.bonj...@gmail.com> wrote:

> Hello all,
>
> I'd like to know if there is an easy way to get the week number from a
> Date object. In pure Java, the Calendar class does the trick via a
> call to get(Calendar.WEEK_OF_YEAR); but the Calendar class is not
> available in GWT.
>
> Any idea?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to google-web-tool...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-toolkit+unsubscr...@googlegroups.com<google-web-toolkit%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>


-- 
*Stefano Ciccarelli*
stef...@indacosoftware.it

*Indaco srl*
via Sabin, 22 - 40017 San Giovanni in Persiceto (BO) - Italy
tel. +39.051.827762 - fax +39.051.6874570
i...@indacosoftware.it
www.indacosoftware.it

*- This e-mail is confidential and may be read, copied and used only by the
intended recipient. If you have received it in error, please contact the
sender immediately by return e-mail. Please then delete the e-mail and do
not disclose its contents to any other person.

- Le informazioni contenute in questa comunicazione sono riservate e
destinate esclusivamente alla/e persona/e o all'ente sopra indicati. E'
vietato ai soggetti diversi dai destinatari qualsiasi uso, copia, diffusione
di quanto in esso contenuto sia ai sensi dell'art. 616 c.p., sia ai sensi
del DL n. 196/03. Se questa comunicazione Vi e' pervenuta per errore, Vi
preghiamo di rispondere a questa e-mail e successivamente cancellarla dal
Vostro sistema.*

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to