使用完整

时间:2017-09-12 17:17:49

标签: typescript

我在typescript

中有这样的函数
setQuitDetails() {
    var currentDate = new Date().toLocaleDateString();
    this.TodaysDate = currentDate;
}

返回此9/12/2017

之类的日期

我想返回日期September 12, 2017

如何在打字稿文件中实现这一目标?

2 个答案:

答案 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