我想以字符串格式比较两个日期,并将结果以 HH:MM:SS:SSS 作为字符串返回。15 Jul 2013 17:08:34.903
当我尝试使用 startDate和 endDate
运行以下命令时,15 Jul 2013 17:08:51.247
我希望看到00:00:16.344
. 相反,我得到了01:00:16.344
. 任何想法为什么会这样?
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("d MMM yyyy HH:mm:ss.SSS");
private static final SimpleDateFormat DATE_FORMAT_HH_MM_SS = new SimpleDateFormat("HH:mm:ss.SSS");
public String calculateDuration(String startDateStr, String endDateStr){
String methodName = "calculateDuration";
try {
Date startDate = DATE_FORMAT.parse(startDateStr);
Date endDate = DATE_FORMAT.parse(endDateStr);
long diff = endDate.getTime() - startDate.getTime();
return DATE_FORMAT_HH_MM_SS.format(diff);