您的位置:首页 > Web前端 > JavaScript

js 时间戳 与 字符串 和 日期格式 的转换

2018-03-29 17:36 666 查看
日期转时间戳:

var newDate=parseInt(new Date().getTime().toString());
var strDate = '2018-03-30 11:47:12';

//字符串转日期格式,strDate要转为日期格式的字符串
function getDate(strDate){
var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,
function (a) { return parseInt(a, 10) - 1; }).match(/\d+/g) + ')');
return date;
}
//时间戳转日期格式
var  handleDate =1522315759934
function getYYYYmmssdate(handleDate) { var now = new Date(handleDate), y = now.getFullYear(), m = now.getMonth() + 1, d = now.getDate(); return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + now.toTimeString().substr(0, 8); }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: