开发者

The way to get day of week, pacific time

I need to write a method to get day of week (pacific time) for current time. Is the following code correct?

static Calendar s_calendar = Calendar.getInstance(Locale.US);
static {
    s_calendar.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
}

public static int getDayOfWeek() {
    s_calendar.setTimeInMillis(S开发者_开发知识库ystem.currentTimeMillis());
    return s_calendar.get(Calendar.DAY_OF_WEEK);
}

Thanks.


Use below:

Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("America/Los_Angeles"),
    Locale.US);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);


System.currentTimeMillis() returns the millis in UTC. Convert it before you call get(Calendar.DAY_OF_WEEK)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜