0
這裏是我的代碼:神祕的timstamp的getTime DIFF
System.out.println(" serverStartTime:" + serverStartTime + " serverRunningTime:" + serverRunningTime);
Timestamp sTime = convertTimeFormat(serverStartTime, "MMM d, yyyy H:mm:ss a z");
Timestamp eTime = convertTimeFormat(serverRunningTime, "MMM d, yyyy H:mm:ss a z");
long diff = (eTime.getTime() - sTime.getTime());
System.out.println("eTime.getTime():" + eTime.getTime() + " sTime.getTime():" + sTime.getTime() + " Time diff:" + diff);
的convertTime樣子:
private Timestamp convertTimeFormat(String msgDate, String srcDateFormat) {
SimpleDateFormat sdf = new SimpleDateFormat(srcDateFormat);
SimpleDateFormat output = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date d = sdf.parse(msgDate);
String formattedTime = output.format(d);
return Timestamp.valueOf(formattedTime);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
輸出是:
serverStartTime:Sep 22, 2016 12:42:56 AM PDT serverRunningTime:Sep 22, 2016 1:33:42 AM PDT
eTime.getTime():1474533222000 sTime.getTime():1474573376000 Time diff:-40154000
通知,運行時間值越小然後開始時間。爲什麼?