我正在尝试将 System.currentTimeMillis 转换为 (hh:mm:ss) 的当前时间格式。到目前为止,这是我尝试过的,但效果不佳。
Long currentTime = System.currentTimeMillis();
int hours;
int minutes;
int seconds;
String getSecToStr = currentTime.toString();
String getTimeStr = getSecToStr.substring(8,13);
seconds = Integer.parseInt(getTimeStr);
minutes = seconds / 60;
seconds -= minutes * 60;
hours = minutes / 60;
minutes -= hours * 60;
String myResult = Integer.toString(hours) + ":" + Integer.toString(minutes) + ":" + Integer.toString(seconds);
System.out.println("Current Time Is: " + myResult);
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?非常感激!