3 回答
TA贡献1802条经验 获得超4个赞
您可以使用矩库。试试这个:
let moment = require('moment');
let dateString = "2020-08-01 11:53:25.85088067 +0000 UTC m=+154637.818754072"
dateString = dateString.split("+")[0];
let date = new Date(dateString);
let formattedDate = moment(date).format('Do MMMM YYYY, h:mm:ss a');
console.log(formattedDate); //1st August 2020, 11:53:25 am
TA贡献1808条经验 获得超4个赞
const dateTimeString = "2020-08-01 11:53:25.85088067 +0000 UTC m=+154637.818754072"
const dateTimeArray = dateTimeString.split(' ')
const [date, time] = dateTimeArray
const dateArray = date.split('-')
const timeArray = time.split(':')
const [year, month, day] = dateArray
const [hour, minute, second] = timeArray
const utcDate = new Date(Date.UTC(year, month - 1, day, hour, minute, second));
console.log(utcDate.toUTCString())
console.log(utcDate.getTime() / 1000)
TA贡献1806条经验 获得超5个赞
如果你想要秒中的值,那么:
Math.floor(新日期('2011-03-29 17:06:21 UTC') / 1000); 它会给你秒的 Unix 时间..(在上面的例子中:1301418381)
如果你想要完整的日期对象:根据 mdn ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC ) 使用这个:
var dateString = "2020-08-01 11:53:25.85088067 +0000 UTC m=+154637.818754072"
dateString.toUTCString()
如果我理解错了问题,请评论或回复,以便我正确理解。谢谢
添加回答
举报