美文网首页
日期格式

日期格式

作者: 苍老师的眼泪 | 来源:发表于2022-08-08 10:41 被阅读0次

Not all browsers support the same date formats. The best approach is to split the string on the separator characters (-, and :) instead, and pass each of the resulting array items to the Date constructor:

var arr = "2010-03-15 10:30:00".split(/[- :]/)
var date = new Date(arr[0], arr[1]-1, arr[2], arr[3], arr[4], arr[5]);

console.log(date);
//-> Mon Mar 15 2010 10:30:00 GMT+0000 (GMT Standard Time)

相关文章

网友评论

      本文标题:日期格式

      本文链接:https://www.haomeiwen.com/subject/vyqnwrtx.html