如何在gwt中获得一年中的一周
How to get week of year in gwt
如何在 gwt 中获取一年中的第几周?我试图获得一年中的一周,但无法获得。请指导我。
我试过使用下面的代码,但它打印的是一天中的一周而不是全年。
DateTimeFormat format = DateTimeFormat.getFormat("c");
String dayOfWeek = format.format(new Date());
E12CommonUtils.printOnConsole("dayOfWeek ="+dayOfWeek);
下面将按照您的要求执行。
Date date = new Date();
Date yearStart = new Date(date.getYear(), 0, 0);
double week = (date.getTime() - yearStart.getTime())/(double)(7 * 24 * 60 * 60 * 1000);
System.out.println((int)Math.ceil(week));
如何在 gwt 中获取一年中的第几周?我试图获得一年中的一周,但无法获得。请指导我。 我试过使用下面的代码,但它打印的是一天中的一周而不是全年。
DateTimeFormat format = DateTimeFormat.getFormat("c");
String dayOfWeek = format.format(new Date());
E12CommonUtils.printOnConsole("dayOfWeek ="+dayOfWeek);
下面将按照您的要求执行。
Date date = new Date();
Date yearStart = new Date(date.getYear(), 0, 0);
double week = (date.getTime() - yearStart.getTime())/(double)(7 * 24 * 60 * 60 * 1000);
System.out.println((int)Math.ceil(week));