I am trying to get a Date instance with UTC using the following code:
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
Date now = cal.getTime();
It looks so simple, but if I check the values in the IntelliJ debugger, I get different dates for caland now:
cal: java.util.GregorianCalendar [time = 1405690214219, areFieldsSet = true, soft = true, zone = GMT, firstDayOfWeek = 2, minimalDaysInFirstWeek = 4, ERA = 1, = 2014 YEAR, MONTH = 6, WEEK_OF_YEAR = 29, WEEK_OF_YEAR = 29, WEEK_OFONYON = 3, 3EEKTH , DAY_OF_MONTH = 18, day_of_year = 199, DAY_OF_WEEK = 6, DAY_OF_WEEK_IN_MONTH = 3, AM_PM = 1, HOUR = 1, HOUR_OF_DAY = 13 , minute = 30, SECOND = 14, milliseconds = 219ST_OF_OF_OF_OF_OF_OF_OF_OF_OF_OF_OF_OF0_OF_OF_OF_OF_OF_OF_OF_O
now: Fri Jul 18 10:30:14 BRT 2014
as you can see, cal3 hours ahead now... what am I doing wrong?
Thanks in advance.
[EDIT] Looks like TimeZone.setDefault(TimeZone.getTimeZone("UTC"));before the code above does the job ...