var getFormattedDateText = function (dateString) {
var date = new Date(dateString);
var hours, am_pm, minutes, time;
//Code for formatting the time starts
hours = date.getHours() > 12 ? date.getHours() - 12 : date.getHours();
am_pm = date.getHours() >= 12 ? "PM" : "AM";
hours = hours < 10 ? "0" + hours : hours;
minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
time = hours + ":" + minutes + " " + am_pm;
//Code for formatting the time ends
var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"];
console.log(date.getHours() + "=" + date.getMinutes());
return (monthNames[date.getMonth()] + ' ' + date.getDate() +' at ' + time+' Local Time');
};
這裏datestring是2017-03-02T09不同的值:00:00,.getDate()和.getMinutes返回在鉻和Firefox
但在Chrome它給date.gethours ()= 14和date.getMinutes = 30
而在Firefox date.gethours()= 09和date.getMinutes = 00
[在Chrome中不正確的Javascript日期VS火狐(可能的重複http://stackoverflow.com/questions/17334602/incorrect-javascript-date-in-chrome -vs-firefox) –