沒有直接的方法從天然Date對象獲取月份名稱和日期名稱的字符串化版本。你需要保持月份名稱和日期名稱的數組,並從中查詢。
$(function(){
$("#get").click(function (e) {
e.preventDefault();
var fDate = getDateFormatted($('input:text').val());
$('#msg').html(fDate);
});
});
function getDateFormatted(dateString)
{
date = new Date(dateString);
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var monthNames = ["January", "February", "March", "April", "May", "June", "July",
"August", "September", "October","November", "December"];
var day=date.getDay();
var dayName = days[day+1];
var monthIndex = date.getMonth();
var year = date.getFullYear();
return dayName + ', ' + monthNames[monthIndex+1] + ' ' + date.getDate();
}
Here是工作示例。
取看看['toLocaleString()'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString),它可以完成你正在尋找的東西正確的選擇。請參閱[this](http://stackoverflow.com/a/21748457/798634)SO使用答案。 –
@MattK - 一個很好的資源。謝謝你,先生! – webfrogs