5
我現在面臨的格式毫秒至SimpleDate格式時怪異的結果:格式毫秒simpledate格式
輸出是:
Start date time: 11/06/30 09:45:48:970
End date time: 11/06/30 09:45:52:831
Execution time: 01:00:03:861
腳本:
long dateTimeStart = System.currentTimeMillis();
// some script execution here
long dateTimeEnd = System.currentTimeMillis();
"Start date time: " + GlobalUtilities.getDate(dateTimeStart, "yy/MM/dd hh:mm:ss:SSS");
"End date time: " + GlobalUtilities.getDate(dateTimeEnd, "yy/MM/dd hh:mm:ss:SSS");
"Execution time: " + GlobalUtilities.getDate((dateTimeEnd - dateTimeStart), "hh:mm:ss:SSS");
方法:
public static String getDate(long milliseconds, String format)
{
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(milliseconds);
}
任何想法爲什麼執行時間值如此關閉?它應該是00:00:03:861,而不是01:00:03:861
感謝
我該如何解決這個問題? – user706058
這是另一個stackoverflow答案與一些非常好的想法! http://stackoverflow.com/questions/625433/how-to-convert-milliseconds-to-x-mins-x-seconds-in-java –
此外,作爲一個方面說明,我可以真正推薦JodaTime API時處理日期在Java中。它實際上比內置的Java日期更好。 http://joda-time.sourceforge.net/ –