Android DatePicker- GregorianCalendar - 00:00:00 UTC - getTimeInMillis()

时间:2016-06-07 11:35:45

标签: android date datetime android-studio calendar

如何将GregorianCalendar的时间设置为00:00:00 UTC?

因为以下内容在晚上10点返回日期:

TimeZone timeZone = TimeZone.getTimeZone("UTC");
Calendar cal = Calendar.getInstance(timeZone);
cal = new GregorianCalendar(year, monthOfYear, dayOfMonth ,0 ,0, 0);
editor.putString("auswahldatum", String.valueOf(cal.getTimeInMillis() / 1000))
      .apply();
Log.i("Kalender", String.valueOf(cal.getTimeInMillis()));

1 个答案:

答案 0 :(得分:1)

查看日历的Calendar.getInstance(timeZone)方法,它已经返回了格里高利历的新对象。你可以像这样创建它:

Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(timezone);

Calendar cal = new GregorianCalendar(year, monthOfYear, dayOfMonth ,0 ,0, 0);
cal.setTime(date);
cal.setTimeZone(timezone);

实际上,您必须在时间设置

后设置时区