1

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/

Shubham Nigam
  • 3,844
  • 19
  • 32
  • possible duplicate of [Using AngularJS date filter with UTC date](http://stackoverflow.com/questions/20662140/using-angularjs-date-filter-with-utc-date) – JJJ Jun 26 '15 at 10:12
  • That was not i actually want ..My problem is may similar to this but that is something which is not helping me out – Shubham Nigam Jun 26 '15 at 10:16
  • Your time is in UTC. If you want to show it as it is, then the duplicate will show how. Otherwise you'll have to change the input to include your timezone. – JJJ Jun 26 '15 at 10:16
  • 1
    my angular is v1.1 in which i can not provide timezone with it – Shubham Nigam Jun 26 '15 at 10:19
  • [o rly?](http://jsfiddle.net/obv10wd9/3/) – JJJ Jun 26 '15 at 10:20
  • Can you please provide me some solution I have added fiddle . – Shubham Nigam Jun 26 '15 at 10:23
  • To which timezone the date is given "2015-06-26T18:50:07.000Z" belongs or it is randomly generated? – RIYAJ KHAN Jun 26 '15 at 10:24
  • Randomly genrated may be because it is generated by google script ,I dont to know timezone.. – Shubham Nigam Jun 26 '15 at 10:26
  • The Z at the end means it's UTC. Which in turn means that the [duplicate's solution](http://stackoverflow.com/questions/20662140/using-angularjs-date-filter-with-utc-date) will work here too. – JJJ Jun 26 '15 at 10:28
  • I have opened that solution may time but what i want to say to you is ,I failded to get what there answers are.. Please update my fiddle if you know how this can be done.. while I will also try do it with that duplicate answer – Shubham Nigam Jun 26 '15 at 10:32
  • 2
    I have copy-pasted the function from the duplicate to you fiddle and it works just fine. http://jsfiddle.net/obv10wd9/7/ – JJJ Jun 26 '15 at 10:57
  • thanks @Juhana all I was doing was not converting into date object – Shubham Nigam Jun 26 '15 at 11:04

1 Answers1

0

Please check this one.

You can do like this.

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

Here is the updated Fiddle

RIYAJ KHAN
  • 15,032
  • 5
  • 31
  • 53