本文操作环境:windows7系统、vue2.9.6版、dell g3电脑
vuejs怎么实现字符串转日期?
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 18:08:40 gmt+0800 (中国标准时间) moment(new date(parseint('1508234920433'))).format("yyyy-mm-dd hh:mm:ss") //2017-10-19 06:08:40
5.vue中怎么使用moment格式转换日期?
1)先安装moment包:npm install moment
2)在组件中引入moment: import moment from moment
3)在组件中使用:let str = moment(new date()).format(yyyy-mm-dd hh:mm:ss) // 2018-04-24 09:55:40
推荐学习:《最新的5个vue.js视频教程精选》
以上就是vuejs怎么实现字符串转日期的详细内容。
