我想将 TimeUnit 转换为 seconds 或 hours ,我问了很多但没有得到满意的答案。 我读过http://developer.android.com/reference/java/util/concurrent/TimeUnit.html#toHours(long)但我不明白使用 示例:
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);
我想将“diffInSec”的值转换为秒、小时
最佳答案
将天转换为小时,应该是 TimeUnit.DAYS.toHours(days)
。
对于其他类型,更改源时间单位的枚举值。
关于android - 如何将 TimeUnit 转换为秒或小时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31197811/