Johannes Müller Johannes Müller - 5 months ago 36
Android Question

Android DatePicker- GeorgianCalendar - 00:00:00 UTC -getTimeinMillis()

How do I set the Time of the GeorgianCalendar to 00:00:00 UTC?

Because the following, returns a Date at 10:00pm:

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));
editor.apply();
Log.i("Kalender", String.valueOf(cal.getTimeInMillis()));

Answer

Look at Calendar Calendar.getInstance(timeZone) method it already return of new object of gregorian calendar; You can create it for example like this one:

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

Or

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

Actually you must set time zone after time setting

Comments