Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: calendar.setTimeInMillis() returns wrong HOUR_OF_DAY value

I am trying to convert my time in minutes to HH:MM. For example 418minutes = 6:58. I am using 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? Thank you very much.

like image 679
Martin Nemeth Avatar asked Mar 04 '13 13:03

Martin Nemeth


1 Answers

Create your Calendar with correct time zone:

Calendar calendar1 = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
like image 172
kamituel Avatar answered Oct 31 '22 21:10

kamituel