Chrome和IE的日期返回值不同?

时间:2015-08-24 13:20:34

标签: javascript angularjs

在chrome fucntion中返回我的错误并在IE中返回我的真实。任何建议为什么会发生这种情况?我发布了图片以查看我得到的内容。 enter image description here

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;
   }

1 个答案:

答案 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);
}