在chrome fucntion中返回我的错误并在IE中返回我的真实。任何建议为什么会发生这种情况?我发布了图片以查看我得到的内容。
var _convertFromUTC = function(ticketTimeCreated) {
var offset = new Date(ticketTimeCreated).getTimezoneOffset() / 60;
var hours = new Date(ticketTimeCreated).getHours();
ticketTimeCreated = new Date(ticketTimeCreated).setHours(hours - offset);
return new Date(ticketTimeCreated);
}
var _checkForTimeDiference = function(ticketTimeCreated) {
var currentDate = new Date();
var formatedDate = _convertFromUTC(ticketTimeCreated);
if (formatedDate.getDate() == currentDate.getDate() && formatedDate.getHours() == currentDate.getHours())
if (currentDate.getMinutes() - formatedDate.getMinutes() <= mainConfigService.TicketCancelDuration) {
return true;
}
return false;
}
答案 0 :(得分:0)
当您使用UTC时间戳时,您无需转换它,Date
将为您执行此操作
new Date("2015-08-24T13:10:56") // Mon Aug 24 2015 15:10:56 GMT+0200
像这样的简单函数应该没问题
var _checkForTimeDiference = function(ticketTimeCreated) {
var currentDate = +new Date; // number of milliseconds since January 1, 1970
var ticketDate = +new Date(ticketTimeCreated);
return (currentDate - ticketDate) <= mainConfigService.TicketCancelDuration * (1000*60);
}