Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java calendar method

Tags:

java

android

Why does this keep returning 0?

Calendar calendar = Calendar.getInstance();
calendar.get(Calendar.HOUR_OF_DAY)?
like image 913
ryan Avatar asked Jul 27 '26 19:07

ryan


1 Answers

Calendar.HOUR_OF_DAY will be 0 whenever the hour of the day falls between between midnight and one o'clock in the morning. So chances are, either it is in that time interval wherever you are, or your Android emulator is set up so it thinks you're in that time interval.

If that's not the case, you could try setting the hour to some arbitrary value and then getting it again to check that it's working. To do that, try:

Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 5);
like image 170
Michael Herold Avatar answered Jul 30 '26 07:07

Michael Herold



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!