vue 将字符串转成date类型_JS和vue中日期格式的转换
1.获取当前时间:
var now=new Date(); //Tue Oct 17 2017 18:08:40 GMT+0800 (中国标准时间)
获取当前时间的日期
new Date().getDate() //17
new Date().toLocaleString() //2017/10/17 下午6:08:40
2.引用moment.js将标准时间转化成YYYY-MM-DD hh:mm:ss
var time=moment(new Date()).format("YYYY-MM-DD hh:mm:ss");
//2017-10-17 06:08:40
var time=moment(new Date()).format("DD"); //17
获取当前时间的第二天
moment(new Date().setDate(new Date().getDate()+2)).format("YYYY-MM-DD hh:mm:ss") //2017-10-19 06:08:40
3.将标准时间转换成时间戳
new Date().getTime() //1508234920433
将YYYY-MM-DD日期转换成时间戳
var stringTime = "2014-07-10 10:21:12";
var timestamp2 = Date.parse(new Date(stringTime));
console.log( timestamp2 );// 1500286120000
4.将时间戳转换成标准时间和YYYY-MM-DD
new Date(parseInt(1508234920433))
//Tue Oct 17 2017
1.获取当前时间: var now=new Date(); //Tue Oct 17 2017 18:08:40 GMT+0800 (中国标准时间) 获取当前时间的日期 new Date().getDate() //17 new Date().toLocaleString() //2017/10/17 下午6:08:40 2.引用moment.js将标准时间转化成YYYY-MM-DD hh:mm:ss var time=moment(new Date()).format("YYYY-MM-DD hh:mm:ss"); //2017-10-17 06:08:40 var time=moment(new Date()).format("DD"); //17 获取当前时间的第二天 moment(new Date().setDate(new Date().getDate()+2)).format("YYYY-MM-DD hh:mm:ss") //2017-10-19 06:08:40 3.将标准时间转换成时间戳 new Date().getTime() //1508234920433 将YYYY-MM-DD日期转换成时间戳 var stringTime = "2014-07-10 10:21:12"; var timestamp2 = Date.parse(new Date(stringTime)); console.log( timestamp2 );// 1500286120000 4.将时间戳转换成标准时间和YYYY-MM-DD new Date(parseInt(1508234920433)) //Tue Oct 17 2017