提交 c3aa8065 authored 作者: mry's avatar mry

feat(base): 时间工具类

上级 dffd050f
package org.matrix.testNg.utils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author MRY
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Duration {
/**
* 秒
*/
private Integer second;
/**
* 分
*/
private Integer minute;
/**
* 时
*/
private Integer hour;
}
package org.matrix.testNg.utils;
/**
* @author MRY
*/
public class SecToTime {
public static Duration secToTime(Long time) {
String timeStr = null;
Long hour = 0L;
Long minute = 0L;
Long second = 0L;
if (time <= 0) {
return new Duration(0, 0, 0);
} else {
minute = time / 60;
if (minute < 60) {
second = time % 60;
timeStr = unitFormat(minute) + ":" + unitFormat(second);
} else {
hour = minute / 60;
if (hour > 99) {
return new Duration(59, 59, 99);
}
minute = minute % 60;
second = time - hour * 3600 - minute * 60;
timeStr = unitFormat(hour) + ":" + unitFormat(minute) + ":" + unitFormat(second);
}
}
return new Duration(Integer.parseInt(unitFormat(second)),
Integer.parseInt(unitFormat(minute)),
Integer.parseInt(unitFormat(hour)));
}
private static String unitFormat(Long i) {
String retStr = null;
if (i >= 0 && i < 10) {
retStr = "0" + i;
} else {
retStr = "" + i;
}
return retStr;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论