|
@@ -12,6 +12,7 @@
|
|
|
* D(大写D) 一年中的天数(年份为大写Y起作用) DD-362
|
|
|
* S(大写S) 毫秒 SSS-043
|
|
|
*/
|
|
|
+
|
|
|
export class TimeHelper {
|
|
|
/**
|
|
|
* 获取当前时间戳
|
|
@@ -26,7 +27,15 @@ export class TimeHelper {
|
|
|
* @param formats 时间格式
|
|
|
* 'yyyy年MM月dd日'
|
|
|
*/
|
|
|
- static getTimeString(formats: string) {
|
|
|
-
|
|
|
+ static formatDate(date: Date, format: string) {
|
|
|
+ const replacements: { [key: string]: string } = {
|
|
|
+ YYYY: date.getFullYear().toString(),
|
|
|
+ MM: String(date.getMonth() + 1).padStart(2, "0"),
|
|
|
+ DD: String(date.getDate()).padStart(2, "0"),
|
|
|
+ HH: String(date.getHours()).padStart(2, "0"),
|
|
|
+ mm: String(date.getMinutes()).padStart(2, "0"),
|
|
|
+ ss: String(date.getSeconds()).padStart(2, "0")
|
|
|
+ };
|
|
|
+ return format.replace(/YYYY|MM|DD|HH|mm|ss/g, matched => replacements[matched]);
|
|
|
}
|
|
|
-}
|
|
|
+}
|