如何从java中的时区获取一天

时间:2016-06-20 10:25:57

标签: java date timezone

我的输入将是时区

public/

输出应该是属于那个时区的日子。

String timeZone = currentTimeZone.getID();
timezone = America/Los_Angeles

这是我到目前为止所尝试的内容。

Monday

3 个答案:

答案 0 :(得分:0)

Calendar calendar = Calendar.getInstance();
Calendar LATime = new GregorianCalendar(TimeZone.getTimeZone("America/Los_Angeles"));
LATime.setTimeInMillis(calendar.getTimeInMillis());
int year = LATime.get(Calendar.YEAR);
int month = LATime.get(Calendar.MONTH);
int date = LATime.get(Calendar.DATE);
int dayOfWeek = calender.get(Calendar.DAY_OF_WEEK);

试一试

答案 1 :(得分:0)

您可以使用其他给出整数的答案,然后您可以相应地将其映射到星期几,或者您可以使用SimpleDateFormat打印星期几,如下所示:

SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
Date datetime = new Date();
sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
System.out.println("America/Los_Angeles " + sdf.format(datetime));

希望这有帮助。

答案 2 :(得分:0)

>  String[] days =
>                 {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
>         Calendar calendar = Calendar.getInstance();
>         Calendar LATime = new GregorianCalendar(TimeZone.getTimeZone("America/Los_Angeles"));
>         LATime.setTimeInMillis(calendar.getTimeInMillis());
>         int year = LATime.get(Calendar.YEAR);
>         int month = LATime.get(Calendar.MONTH);
>         int date = LATime.get(Calendar.DATE);
>         int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
>         System.out.println(days[dayOfWeek -1]);

我们也可以设置calendar.setFirstDayOfWeek();默认它是周日的开始。