我想用currentTimeMillis
两次,这样我就可以计算持续时间,但我也想以用户可读的格式显示时间和日期。我遇到了麻烦currentTimeMillis
有利于计算,但我看不到内置函数可以转换为合适的时间或时间/日期。
I use
android.text.format.DateFormat df = new android.text.format.DateFormat();
df.format("yyyy-MM-dd kk:mm:ss", new java.util.Date());
为了产生好的时间和日期,我最终想做的是展示我的结果currentTimeMillis
值转化为android.text.format.DateFormat df = new android.text.format.DateFormat();
e.g.
android.text.format.DateFormat df = currentTimeMillis();
当我尝试时我得到
类型不匹配:无法从 long 转换为 DateFormat
我尝试使用一些铸造,但不知道如何实现这一点。
它会起作用的。
long yourmilliseconds = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
Date resultdate = new Date(yourmilliseconds);
System.out.println(sdf.format(resultdate));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)