add Time.toString
This commit is contained in:
@ -69,6 +69,26 @@ export default class Time {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将毫秒值转换为可读的时间字符串
|
||||||
|
*
|
||||||
|
* @param ms 毫秒值
|
||||||
|
* @return 时间字符串,如 "10 天"、"5 小时"、"30 分钟"、"15 秒"、"500 毫秒"
|
||||||
|
*/
|
||||||
|
public static toString(ms: number): string {
|
||||||
|
if (Time.D <= ms) {
|
||||||
|
return `${Math.floor(ms / Time.D)} 天`;
|
||||||
|
} else if (Time.H <= ms) {
|
||||||
|
return `${Math.floor(ms / Time.H)} 小时`;
|
||||||
|
} else if (Time.M <= ms) {
|
||||||
|
return `${Math.floor(ms / Time.M)} 分钟`;
|
||||||
|
} else if (Time.S <= ms) {
|
||||||
|
return `${Math.floor(ms / Time.S)} 秒`;
|
||||||
|
} else {
|
||||||
|
return `${Math.floor(ms)} 毫秒`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static between(begin: Date, end?: Date) : any {
|
public static between(begin: Date, end?: Date) : any {
|
||||||
if (!end) {
|
if (!end) {
|
||||||
end = new Date();
|
end = new Date();
|
||||||
|
|||||||
Reference in New Issue
Block a user