我正在使用node.js和ejs。我有數據響應像日期在另一個國家/地區顯示一天?
[{"message":"","fileSize":"2132","id":"4225","readBy":"2016-03-01 09:04:50","userID":"23","dateTime"
:"2016-03-01 09:03:57","fileName":"movie.mov","fileTicketID":"e0219f64-fb43-4302-8ec3-848a98545048"}
,{"message":"","fileSize":"64132","id":"4226","readBy":"2016-03-01 09:04:50","userID":"23","dateTime"
:"2016-03-01 09:04:20","fileName":"spanish.rtf","fileTicketID":"905f9905-c406-4514-9410-0443c4baa570"
},{"message":"","fileSize":"93430","id":"4227","readBy":"2016-03-01 10:21:07","userID":"23","dateTime"
:"2016-03-01 09:06:08","fileName":"IP estatica.tiff","fileTicketID":"f9bd81a8-b022-4d53-94e7-8301d30ae5e3"
},{"message":"","fileSize":"45","id":"4228","readBy":"2016-03-01 10:21:07","userID":"23","dateTime":"2016-03-01
09:06:22","fileName":"Text File.txt","fileTicketID":"85a6adb6-15a9-4742-b7d2-05fcd3fa23c1"}]
我需要顯示的數據日期組明智的。
我不喜歡下面
var map = {};
msg1.forEach(function(a){
var key = a.dateTime.substring(0, 10);
map[key] = map[key] || [];
map[key].push(a);
});
Object.keys(map).forEach(function(date){
var dt = new Date(date),
monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var dateStr = dt.getDate() + " " + monthNames[dt.getMonth()] + ", " + dt.getFullYear();
alert(dateStr);
var el1 = $('<span>' + dateStr + '</span>');
$(".chat_window ul").append(el1);
map[date].forEach(function(item){
//item is the each value in array
// alert(item.message);
var now = item.dateTime;
var jsDate = toJSDate(now);
//var dd = jsDate.toLocaleDateString() + " " + jsDate.toLocaleTimeString();
var msgtime = jsDate.toLocaleTimeString();
msgtime = msgtime.replace(/:\d+ /, ' ');
var el = $('<li class="message right appeared"><div class="avatar"><img src="' + url +
'/getUserImage/' + item.userID + '/60"/></div><div class="text_wrapper"><div class="text">' +
item.message + '</div><span>' + msgtime + '</span></div></li>');
});
在我結束所有的東西還行它的顯示日期以及在我結束。但在我的 客戶端,它顯示的是一天前的日期。正如你我已經有日期 作爲迴應,只需要以明智的方式格式化或分組數據。那麼爲什麼 它顯示有一天回來。這只是因爲javascript日期 函數?
在DB如何存儲?一天回來? – Subburaj
沒有像上面的迴應,你可以在數據庫中看到它的保存「2016-06-22 09:06:22」,當我改變它的格式,然後在我的結尾它的節目2016年6月22日,但在我的客戶端結束其節目20,他的cuntry是美國 –
有沒有什麼辦法在我的系統中檢查另一個國家的代碼 –