一、js Date对象、时间戳之间转换
1.js Date对象转时间戳
var now = new Date();
//js Date对象转时间戳
var timeKey = now.getTime(); //1605334977352
console.info(timeKey);
2.js 时间戳 转 Date对象
//js 时间戳 转 Date对象
var timeOne = new Date(1605334977352);
console.info(timeOne); //Sat Nov 14 2020 14:22:57 GMT+0800 (中国标准时间)
二、js Date对象、时间字符串之间转换
1.js 字符串转Date对象
//js 时间字符串 转 时间对象
//中文间隔不支持 例如:2020年10月1日
var timeTwo = new Date('2020-10-1');
console.info(timeTwo.toLocaleString()); //2020/10/1 上午12:00:00
var timeThree = new Date('2020-11-1 08:30');
console.info(timeThree.toLocaleString()); //2020/11/1 上午8:30:00
var timeFourth=new Date('2020/12/10 10:15');
console.info(timeFourth.toLocaleString()); //2020/12/1