I'm trying to get my app to display a time, and for that I need to get the android's minutes and hours. I'm trying to use currentTimeMillis()
, but I'm getting the wrong number for the hours. Here's my code for the hours and minutes using the systems clock.
int defday = (int) (System.currentTimeMillis() / (1000 * 60 * 60 * 24));
int defhour = (int) (System.currentTimeMillis() - (defday * 1000 * 60 * 60 * 24))
/ (1000 * 60 * 60);
int defmin = (int) (System.currentTimeMillis()
- (defhour * 1000 * 60 * 60) - (defday * 1000 * 60 * 60 * 24))
/ (1000 * 60);
After I run the app, the time shows the time as 5:36
even though the current time is 1:36
. What am I doing wrong?