问题:
The code below gives me the current time. 下面的代码为我提供了当前时间。 But it does not tell anything about milliseconds. 但这并不能说明毫秒。
public static String getCurrentTimeStamp() {
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//dd/MM/yyyy
Date now = new Date();
String strDate = sdfDate.format(now);
return strDate;
}
I get date in the format 2009-09-22 16:47:08
(YYYY-MM-DD HH:MI:Sec) . 我以2009-09-22 16:47:08
(YYYY-MM-DD HH:MI:Sec)的格式获取日期。
But I want to retrieve the current time in the format 2009-09-22 16:47:08.128
((YYYY-MM-DD HH:MI:Sec.Ms)- where 128 tells the millisecond. 但是我想以2009-09-22 16:47:08.128
((YYYY-MM-DD HH:MI:Sec.Ms))的格式检索当前时间-其中128表示毫秒。
SimpleTextFormat
will work fine. SimpleTextFormat
将正常工作。 Here the lowest unit of time is second, but how do I get millisecond as well? 在这里,最小的时间单位是秒,但是如何获得毫秒呢?
解决方案:
参考一: https://stackoom.com/question/67iq/如何在Java中以YYYY-MM-DD-HH-MI-秒毫秒格式获取当前时间参考二: https://oldbug.net/q/67iq/How-to-get-the-current-time-in-YYYY-MM-DD-HH-MI-Sec-Millisecond-format-in-Java
来源:oschina
链接:https://my.oschina.net/u/4432649/blog/4404388