Ignore Time Zone Angularjs

后端 未结 3 467
别跟我提以往
别跟我提以往 2021-01-02 19:18

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) {
    $         


        
3条回答
  •  旧时难觅i
    2021-01-02 20:12

    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:

    {{ date | utc | date:'yyyy-MM-dd HH:mm:ss' }}
    

提交回复
热议问题