Reputation: 41
I want to convert TimeUnit to seconds or hours , I've asked a lot but do not get a satisfactory answer. I've read on http://developer.android.com/reference/java/util/concurrent/TimeUnit.html#toHours(long) but I don't understand to use example:
String strfileDate = "2012-04-19 15:15:00";
DateFormat formatter2 = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
Date da =formatter2.parse(strFileDate);
long diffInMs = da.getTime() - new Date(System.currentTimeMillis()).getTime();
long diffInSec = TimeUnit.MILLISECONDS.toSeconds(diffInMs);
I want to convert valuse of "diffInSec" to Seconds, hours
Upvotes: 3
Views: 5709
Reputation: 443
convert day to hours, should be TimeUnit.DAYS.toHours(days)
.
for other type, change Enum value for source time unit.
Upvotes: 5