我在typescript
中有这样的函数setQuitDetails() {
var currentDate = new Date().toLocaleDateString();
this.TodaysDate = currentDate;
}
返回此9/12/2017
我想返回日期September 12, 2017
如何在打字稿文件中实现这一目标?
答案 0 :(得分:1)
如果正在运行,请尝试此操作:
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var setQuitDetails = function() {
var currentDate = new Date();
this.TodaysDate = currentDate;
var year = this.TodaysDate.getFullYear();
var month = months[this.TodaysDate.getMonth()];
var day = this.TodaysDate.getDay();
var output = month + ' ' + day + ', ' + year;
alert(output);
return output;
}
setQuitDetails();
答案 1 :(得分:1)
您可以通过toLocaleString
:
const options = {
month: 'long',
day: 'numeric',
year: 'numeric'
}
console.log(new Date().toLocaleString("en-US", options)));
==> September 12, 2017