1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > js中国标准时间转化为年月日 时间戳

js中国标准时间转化为年月日 时间戳

时间:2022-03-19 00:41:51

相关推荐

js中国标准时间转化为年月日 时间戳

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);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。