这是我显示应用程序正常运行时间的代码:
/**
* Gets the uptime of the application since the JVM launch
* @return The uptime in a formatted String (DAYS, MONTHS, MINUTES, SECONDS)
*/
public static String getGameUptime() {
RuntimeMXBean mxBean = ManagementFactory.getRuntimeMXBean();
DateFormat dateFormat = new SimpleDateFormat("dd:HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+0"));
return dateFormat.format(new Date(mxBean.getUptime()));
}
但是当应用程序只运行了 3 分 50 秒时,它会返回一个“01:00:03:50”。在这种情况下,01 应该是 00。这是什么原因?我该如何解决?