user2983041
user2983041

Reputation: 1861

Android, actual hour issue

I use the following code to get hour in Android devices, and works well.

Calendar now = Calendar.getInstance();

int hour = now.get(Calendar.HOUR_OF_DAY);

But I have a 4.1.2 device that don´t work, because the hour given is not in 24 hours mode. For example, if actual hour is 18:32, return 6:32. The time of this device is properly set from the device settings menu. Moreover I have on and off the network time, from settings menu, and the result is the same.

Thanks.

Upvotes: 0

Views: 50

Answers (1)

asgs
asgs

Reputation: 3984

You could use the AM_PM field in the Calendar instance. It will return either AM or PM, based on which you could add 12 hours to it or take it as such.

To maintain compatibility with other devices, it's better to use HOUR (instead of HOUR_OF_DAY) in conjunction with AM_PM.

Upvotes: 1

Related Questions