const data1 = 'Fri Jan 10 18:52:45 GMT+0800 (中国标准时间)'/*** @function 中国标准时间转化为时间戳* @param {string} date* @returns {number} 时间戳* @author 天心天地生 -1-14* */function dateToMs(date) {let result = new Date(date).getTime();return result;}const data1_timestamp = dateToMs(data1);console.log('timestamp', dateToMs(data1)); // > timestamp 1578653565000/*** @function 时间戳转化为年月日* @param {string} date* @returns {number} 时间戳* @author 天心天地生 -1-14* */const transformTimestamp = (timestamp) => {const date = new Date(timestamp);const Y = date.getFullYear() + '-';const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';const D = date.getDate() + ' ';const h = date.getHours() + ':';const m = date.getMinutes();// const s = date.getSeconds(); // 秒const dateString = Y + M + D + h + m;console.log('dateString', dateString); // > dateString -01-10 18:52return dateString;}transformTimestamp(data1_timestamp);
1200字范文,内容丰富有趣,写作的好帮手!