日期格式轉換
2020-06-27T14:20:27.000000Z 時間格式轉換成 2020-06-27 14:20:27
function rTime(date) { var json_date = new Date(date).toJSON(); return new Date(new Date(json_date) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '') } let date = rTime('2020-06-27T14:20:27.000000Z'); console.log(date) // 2020-06-27 14:20:27
toJSON() 方法可以將 Date 對象轉換為字符串,並格式化為 JSON 數據格式。
