12345678910111213141516171819202122232425262728293031323334353637 |
- export const TimeUtil = {
- dateFormat: function (strDate: any, strFormat: any) {
- return FormatDate(strDate, strFormat);
- }
- }
- function FormatDate(strDate: any, strFormat?: any) {
- if (!strDate) return 'strDate==null';
- if (!strFormat) strFormat = "yyyy-MM-dd"
- switch (typeof strDate) {
- case "string":
- strDate = new Date(strDate.replace(/-/g, "/"));
- break;
- case "number":
- strDate = new Date(strDate);
- break;
- }
- if (strDate instanceof Date) {
- const dict: any = {
- yyyy: strDate.getFullYear(),
- M: strDate.getMonth() - 1,
- d: strDate.getDate(),
- H: strDate.getHours(),
- m: strDate.getMinutes(),
- s: strDate.getSeconds(),
- MM: ("" + (strDate.getMonth() + 101)).substring(1),
- dd: ("" + (strDate.getDate() + 100)).substring(1),
- HH: ("" + (strDate.getHours() + 100)).substring(1),
- mm: ("" + (strDate.getMinutes() + 100)).substring(1),
- ss: ("" + (strDate.getSeconds() + 100)).substring(1),
- };
- return strFormat.replace(/(yyyy|MM?|dd?|HH?|ss?|mm?)/g, function () {
- return dict[arguments[0]]
- })
- }
- }
|