在我的代码中,我正在生成长毫秒的时间戳值。我想将其转换为 HH:mm:ss(600000 到 00:10:00),我想显示 hh:mm:ss 格式的差异
String strstart = "8:30:00";
String strend = "8:40:00";
SimpleDateFormat sdf1 = new SimpleDateFormat("hh:mm:ss");
try {
Date date1 = sdf1.parse(strstart);
Date date2 = sdf1.parse(strend);
long durationInMillis = date2.getTime() - date1.getTime();
System.out.println("durationInMillis---->" + durationInMillis);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我使用波纹管代码,输出是0:10:0
这样的,但我想要像这样的输出00:10:00
int seconds = (int) (durationInMillis / 1000) % 60 ;
int minutes = (int) ((durationInMillis / (1000*60)) % 60);
int hours = (int) ((durationInMillis / (1000*60*60)) % 24);
System.out.println(hours+":"+minutes+":"+seconds);