| | |
| | | return time ? moment.unix(time).format(format) : DEFAULT_PLACEHOLDER |
| | | } |
| | | |
| | | export function dateFormat(date:any, format:string) { |
| | | format = format || 'yyyy-MM-dd hh:mm:ss'; |
| | | export function dateFormat (date:any, format:string) { |
| | | format = format || 'yyyy-MM-dd hh:mm:ss' |
| | | if (date !== 'Invalid Date') { |
| | | let o = { |
| | | "M+": date.getMonth() + 1, //month |
| | | "d+": date.getDate(), //day |
| | | "h+": date.getHours(), //hour |
| | | "m+": date.getMinutes(), //minute |
| | | "s+": date.getSeconds(), //second |
| | | "q+": Math.floor((date.getMonth() + 3) / 3), //quarter |
| | | "S": date.getMilliseconds() //millisecond |
| | | const o = { |
| | | 'M+': date.getMonth() + 1, // month |
| | | 'd+': date.getDate(), // day |
| | | 'h+': date.getHours(), // hour |
| | | 'm+': date.getMinutes(), // minute |
| | | 's+': date.getSeconds(), // second |
| | | 'q+': Math.floor((date.getMonth() + 3) / 3), // quarter |
| | | S: date.getMilliseconds() // millisecond |
| | | } |
| | | if (/(y+)/.test(format)) format = format.replace(RegExp.$1, |
| | | (date.getFullYear() + "").substr(4 - RegExp.$1.length)); |
| | | for (let k in o) |
| | | if (new RegExp("(" + k + ")").test(format)) |
| | | if (/(y+)/.test(format)) { |
| | | format = format.replace(RegExp.$1, |
| | | (date.getFullYear() + '').substr(4 - RegExp.$1.length)) |
| | | } |
| | | for (const k in o) { |
| | | if (new RegExp('(' + k + ')').test(format)) { |
| | | format = format.replace(RegExp.$1, |
| | | RegExp.$1.length === 1 ? o[k] : |
| | | ("00" + o[k]).substr(("" + o[k]).length)); |
| | | return format; |
| | | RegExp.$1.length === 1 |
| | | ? o[k] |
| | | : ('00' + o[k]).substr(('' + o[k]).length)) |
| | | } |
| | | } |
| | | return format |
| | | } |
| | | return ''; |
| | | |
| | | return '' |
| | | } |
| | | |
| | | export function convertTimestampToDate(timestamp:any, format:string) { |
| | | if (timestamp && (typeof timestamp === "string") && timestamp.indexOf("-") > -1) { |
| | | timestamp = timestamp.replace(/\-/g, "/") |
| | | export function convertTimestampToDate (timestamp:any, format:string) { |
| | | if (timestamp && (typeof timestamp === 'string') && timestamp.indexOf('-') > -1) { |
| | | timestamp = timestamp.replace(/\-/g, '/') |
| | | } |
| | | let time = new Date(timestamp) |
| | | let formatterTime = dateFormat(time, format) |
| | | const time = new Date(timestamp) |
| | | const formatterTime = dateFormat(time, format) |
| | | return formatterTime |
| | | } |
| | | |
| | |
| | | export const timestampToTime = (timestamp:number) => { |
| | | if (!timestamp) return |
| | | // 时间戳为10位需*1000,时间戳为13位不需乘1000 |
| | | var date = new Date(timestamp); |
| | | var Y = date.getFullYear() + "-"; |
| | | var M = |
| | | const date = new Date(timestamp) |
| | | const Y = date.getFullYear() + '-' |
| | | const M = |
| | | (date.getMonth() + 1 < 10 |
| | | ? "0" + (date.getMonth() + 1) |
| | | : date.getMonth() + 1) + "-"; |
| | | var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()); |
| | | return Y + M + D; |
| | | ? '0' + (date.getMonth() + 1) |
| | | : date.getMonth() + 1) + '-' |
| | | const D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) |
| | | return Y + M + D |
| | | } |