我正在開發移動應用程序並構建我正在使用的日期對象以下日期字符串。但是我需要輸出的時間字符串比輸入時間更奇怪。JavaScript返回時間不正確
錄入時間:
2014-01-09T20:40:00
輸出時間:
10th January, 2:10am
要Constuct我使用日期對象下面的代碼
var date = new Date('2014-01-09T20:40:00');
Dates.getAMPMTimeFromDateObject = function (date) {
var dateSuffix = Constants.Formatting.DateAMSuffix,
hours = date.getHours(),
minutes = date.getMinutes(),
minutesString;
hours = (hours + 24) % 24;
if (hours === 0) {
hours = 12;
} else if (hours > 12) {
hours = hours % 12;
dateSuffix = Constants.Formatting.DatePMSuffix;
} else if (hours === 12) { //This is specific fix for 12PM exceptional case
dateSuffix = Constants.Formatting.DatePMSuffix;
}
minutesString = (minutes < 10) ? '0' + minutes : minutes;
return hours + ':' + minutesString + dateSuffix;
};
你檢查你的時區? – Yunzhou
嘗試使用此api來處理日期[Moment JS](http://momentjs.com/) – Ravi
你能顯示輸出錯誤時間的代碼嗎? – ColinE