忽略时区 Angularjs [英] Ignore Time Zone Angularjs

查看:19
本文介绍了忽略时区 Angularjs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有更好的方法来忽略 Angularjs 中的时区:

2014-01-18 14:30:00"而不是2014-01-18 15:30:00"

function Scope($scope) {$scope.datum = "2014-01-18T14:30:00Z";}<div ng:app ng:controller="Scoper">日期时间 <br/>角度:{{数据|日期:'yyyy-MM-dd HH:mm:ss'}} <br/>

http://jsfiddle.net/samibel/2rMXJ/

解决方案

我找到了这个答案:为什么 angular 日期过滤器将 2 添加到小时?

这是一个示例:

只需管道另一个过滤器:

app.filter('utc', function(){返回函数(val){var date = new Date(val);返回新日期(date.getUTCFullYear(),date.getUTCMonth(),date.getUTCDate(),日期.getUTCHours(),date.getUTCMinutes(),date.getUTCSeconds());};});

在您的模板中:

{{ date |UTC |日期:'yyyy-MM-dd HH:mm:ss' }}</span>

Is there a better way to ignore an timezone in Angularjs:

"2014-01-18 14:30:00" Instead Of "2014-01-18 15:30:00"

function Scoper($scope) {
    $scope.datum = "2014-01-18T14:30:00Z";
}

<div ng:app ng:controller="Scoper">
    DateTime  <br />
    Angular: {{datum | date:'yyyy-MM-dd HH:mm:ss'}} <br />
</div>

http://jsfiddle.net/samibel/2rMXJ/

解决方案

I found this answer: Why does angular date filter adding 2 to hour?

Here is an example:

Just pipe another filter:

app.filter('utc', function(){

  return function(val){
    var date = new Date(val);
     return new Date(date.getUTCFullYear(), 
                     date.getUTCMonth(), 
                     date.getUTCDate(),  
                     date.getUTCHours(), 
                     date.getUTCMinutes(), 
                     date.getUTCSeconds());
  };    

});

In your template:

<span>{{ date | utc | date:'yyyy-MM-dd HH:mm:ss' }}</span>

这篇关于忽略时区 Angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆