0
我在打字稿這樣的功能格式化打字稿日期與月份寫的全
setQuitDetails() {
var currentDate = new Date().toLocaleDateString();
this.TodaysDate = currentDate;
}
它返回這樣9/12/2017
我想回到這樣September 12, 2017
如何在打字稿文件中實現此目的?
我在打字稿這樣的功能格式化打字稿日期與月份寫的全
setQuitDetails() {
var currentDate = new Date().toLocaleDateString();
this.TodaysDate = currentDate;
}
它返回這樣9/12/2017
我想回到這樣September 12, 2017
如何在打字稿文件中實現此目的?
如果正在運行試試這個:
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();
你可以通過toLocaleString
做到這一點:
const options = {
month: 'long',
day: 'numeric',
year: 'numeric'
}
console.log(new Date().toLocaleString("en-US", options)));
==>September 12, 2017