Android : Parse date miliseconds to days,hours,minutes

on Monday, February 16, 2015


I'm trying to get parse a string to date, and after that to get the days,hours,minutes from the miliseconds. I'm parsing this string to date:2015-03-01 00:00:00, and that im doing with this code:



DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date inputDate = dateFormat.parse(data.get(position).getValidTo());
long ms = inputDate.getTime();


Now after this I'm trying to get days,hours,minutes by doing this:



mins=(ms/(1000*60))%60;
hours=(ms/(1000*60*60))%24;
days=(ms/(1000*60*60*24));


and when i display it i get this:


16494Days : 22 hours : 58 minutes, as you can see the days are too far away today is 16-th feb, and the expiring date is 1-st of March.


Can anyone tell me what is wrong here?


0 comments:

Post a Comment