我想在
Android应用程序中获取当前时间(HH:MM:SEC:MILLISEC).我正在使用这段代码:
- Calendar c = Calendar.getInstance();
- int time_start = c.get(Calendar.MILLISECOND);
“获取和设置的字段编号表示小时内的分钟.例如,在10:04:15.250 PM,MILLI为250.”
我已经查看了其他方法,但是我找不到任何指定它会输出所有内容的东西.无论如何我能得到H:M:Sec:MilliSec?或者我只需要做类似的事情
- c.get(Calendar.HOUR).get(Calendar.MINUTE).get(Calendar.SECOND).get(Calendar.MILLISECOND).
解决方法
您可以尝试使用SimpleDateFormat sdf = new SimpleDateFormat(“HH:mm:ss.SSS”);
也许这样:
- Calendar cal = Calendar.getInstance();
- SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
- String test = sdf.format(cal.getTime());
- Log.e("TEST",test);