date.getHours() to calendar.hour
Posted
by
user1487045
on Stack Overflow
See other posts from Stack Overflow
or by user1487045
Published on 2012-10-30T22:59:00Z
Indexed on
2012/10/30
22:59 UTC
Read the original article
Hit count: 108
calendar
I want to get the hour of day in 24hour cycle. I know that date.getHours() is depreciated. But I'm tempted to use it since I cant get the same result out of calendar.hour call. Can anyone tell me how to fix what I have below to get the hours out correctly with calendar.hour? ...much appreciated.
Date d = new Date();
Calendar c = Calendar.getInstance();
c.setTime(d);
System.out.println("hour: "+Math.abs(c.HOUR-24)+", mins: "+Math.abs(c.MINUTE-60)+", d.h: "+d.getHours() +", d.m: "+d.getMinutes());
© Stack Overflow or respective owner