Java: calendar.setTimeInMillis () returns invalid value HOUR_OF_DAY

I am trying to convert my time in minutes to HH: MM. For example, 418minutes = 6:58. I am using the following code:

 long milli = PriemCas*60000;
 Calendar calendar1 = Calendar.getInstance();       
 calendar1.setTimeInMillis(milli);
 int hours3 = calendar1.get(Calendar.HOUR_OF_DAY);
 int minutes3 = calendar1.get(Calendar.MINUTE);

 System.out.println(hours3+":"+minutes3);

I get 7:58 when my variable PriemCas = 418 instead of 6:58. What could be wrong here? Many thanks.

+5
source share
1 answer

Create your Calendar with the correct time zone:

Calendar calendar1 = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+14
source

All Articles