var timestamp = 1527521052; var newDate = new Date(); newDate.setTime(timestamp * 1000); // Mon May 28 2018 console.log(newDate.toDateString()); // Mon, 28 May 2018 15:24:12 GMT console.log(newDate.toGMTString()); // 2018-05-28T15:24:12.000Z console.log(newDate.toISOString()); // 2018-05-28T15:24:12.000Z console.log(newDate.toJSON()); // 2018/5/28 console.log(newDate.toLocaleDateString()); // 2018/5/28 下午11:24:12 console.log(newDate.toLocaleString()); // 下午11:24:12 console.log(newDate.toLocaleTimeString()); // Mon May 28 2018 23:24:12 GMT+0800 (中国标准时间) console.log(newDate.toString()); // 23:24:12 GMT+0800 (中国标准时间) console.log(newDate.toTimeString()); // Mon, 28 May 2018 15:24:12 GMT console.log(newDate.toUTCString());
JS时间格式和时间戳的相互转换
内容版权声明:除非注明,否则皆为本站原创文章。