日期转字符串:
date = new Date()
//第一种是直接toString()
date.toString()
但是格式是这样的:
VM153:3 Thu Sep 28 2017 09:26:05 GMT+0800 (中国标准时间)
有卵用啊这种格式
所以得用第二种:
通过获取年月日来拼接字符串
let date = new Date()
let date_str = date.getFullYear() + "-" +
date.getMonth() + "-" +
date.getDate()
String转Date:
let date_str = "2019-11-11"
let date = new Date(Date.parse(date_str.replace(/-/g, "/")));
// 输出格式就是这样的 不过是Date类型
VM153:3 Thu Sep 28 2017 09:26:05 GMT+0800 (中国标准时间)