Showing wrong date conversion in angular v1.1

时间:2015-06-26 10:04:44

标签: javascript angularjs

I was having time="2015-06-26T18:50:07.000Z" as I am using angularv1.1 ,I can not use UTC and I dont have milliseconds as well, What I have is only this time string

In HTML

<div ng-app='myapp' ng-controller="myctrl">
{{date | date:"MM/dd/yyyy" }}
</div>

In Controller

var x="2015-06-26T18:50:07.000Z"
var app=angular.module('myapp',[]);
app.controller('myctrl',function($scope){
    $scope.date=x;
});

Where I want output as 06/26/2015 and it is showing 06/27/2015 may be problem of GMT or UTC whatever .

Please suggest me ,What can I do to show 06/26/2015

Fiddle:http://jsfiddle.net/obv10wd9/2/

1 个答案:

答案 0 :(得分:0)

请检查一下。

你可以这样做。

var x="2015-06-26T18:50:07.000Z"
var app=angular.module('myapp',[]);
app.controller('myctrl',function($scope){
    var date=new Date(x);  
    $scope.date = new Date(date.getTime() +(date.getTimezoneOffset()*60000));

    console.log(typeof $scope.date)    
});

以下是更新后的Fiddle