【发布时间】:2018-05-10 13:52:52
【问题描述】:
我正在尝试在 Javascript 中转换这种格式的时间戳
/日期(1231110000000)/
转成这种格式:
DD/MM/YYYY
有人知道怎么做吗??
【问题讨论】:
-
为此使用矩库。momentjs.com
标签: javascript date timestamp date-format time-format
我正在尝试在 Javascript 中转换这种格式的时间戳
/日期(1231110000000)/
转成这种格式:
DD/MM/YYYY
有人知道怎么做吗??
【问题讨论】:
标签: javascript date timestamp date-format time-format
如何将/Date(1231110000000)/ 转换为DD/MM/YYYY 格式:
function convert(timestamp) {
var date = new Date( // Convert to date
parseInt( // Convert to integer
timestamp.split("(")[1] // Take only the part right of the "("
)
);
return [
("0" + date.getDate()).slice(-2), // Get day and pad it with zeroes
("0" + (date.getMonth()+1)).slice(-2), // Get month and pad it with zeroes
date.getFullYear() // Get full year
].join('/'); // Glue the pieces together
}
console.log(convert("/Date(1231110000000)/"));
【讨论】:
你的问题不清楚。
如果您在第一个问题中的时间是 EPOCH 时间(从 1970 年过去的秒数),您可以使用 .toISOstring ,这应该可以让您足够接近您想要的。
【讨论】: