java - Resetting time to midnight subtracts one day -


i have following code supposed reset given time in milliseconds midnight of same day. have 2 time instances, 1409097600000l , 1409270400000l, both of @ midnight. however, after passing through reset code, 1 comes out untouched, while other ends in previous day (-86400000). wondering if explain going on. here code:

calendar start = calendar.getinstance(); start.settimezone(timezone.gettimezone("utc")); start.settime(new date(1409097600000l)); // reset hour, minutes, seconds , millis start.set(calendar.hour_of_day, 0); start.set(calendar.minute, 0); start.set(calendar.second, 0); start.set(calendar.millisecond, 0);  system.out.println("all day start: " + start.gettimeinmillis());  calendar end = calendar.getinstance(); end.settime(new date(1409270400000l)); system.out.println("1: " + end.gettimeinmillis()); end.settimezone(timezone.gettimezone("utc")); system.out.println("2: " + end.gettimeinmillis()); // reset hour, minutes, seconds , millis end.set(calendar.hour_of_day, 0); end.set(calendar.minute, 0); end.set(calendar.second, 0); end.set(calendar.millisecond, 0); system.out.println("all day end: " + (end.gettimeinmillis())); 

the output on machine is:

all day start: 1409097600000 1: 1409270400000 2: 1409270400000 day end: 1409184000000 

you're setting timezone of second calendar after setting time. you're setting time in default timezone (presumably local one). change time zone, apparently puts sometime yesterday.

move settimezone line in second instance up, have in first instance.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -