尝试通过执行此操作来显示日期:
let myDate="2015-03-08T04:49:49.431Z";
console.log(new Date(myDate).toUTCString('dd-mm-yyyy'));
仍然返回时间,我该如何才能返回日期?
答案 0 :(得分:1)
var myDate="2015-03-08T04:49:49.431Z";
new Date(myDate).toLocaleDateString(); // "3/8/2015"
new Date(myDate).toDateString(); // "Sun Mar 08 2015"
您可以在此处查看所有其他方法:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
答案 1 :(得分:0)
您可以执行以下操作:
let myDate = "2015-03-08T04:49:49.431Z";
let date = new Date(myDate);
let dateString = ("0" + date.getUTCDate()).slice(-2) + "-" + ("0" + (date.getUTCMonth()+1)).slice(-2) + "-" + date.getUTCFullYear();
console.log(dateString);
.toUTCString()
不接受任何论据。