java - Using Calendar to reset counted steps every midnight -


i building android app counts user's steps. purpose count steps midnight of previous day midnight of each day. how set calendar object. java question really.

calendar cal = calendar.getinstance();     date = new date();     cal.settime(now);     long endtime = cal.gettimeinmillis();     cal.add(calendar.day_of_week, -1);     long starttime = cal.gettimeinmillis();      simpledateformat dateformat = new simpledateformat(date_format);     log.i(tag, "range start: " + dateformat.format(starttime));     log.i(tag, "range end: " + dateformat.format(endtime)); 

and outpup

range start: 2015.05.14 09:25:13 range end: 2015.05.15 09:25:13 

so can see output. count steps between period. if enter few minutes later,the date format like

range start: 2015.05.14 09:27:07 range end: 2015.05.15 09:27:07 

i want

 range start: 2015.05.14 00:00:00  range end: 2015.05.15 00:00:00 

thanks.

first have today's date:

calendar date = new gregoriancalendar(); 

set date tonight (and store it!):

date.set(calendar.hour_of_day, 0); date.set(calendar.minute, 0); date.set(calendar.second, 0); date.set(calendar.millisecond, 0); 

when have midnight, add +1 day tomorrow's

date.add(calendar.day_of_month, 1); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -