I've been struggling with what seems to be a simple task - converting a date string to a date object and formatting it in Angular. Here's the issue:
In my Angular app and controller, I have the following code:
myApp.controller('myAppCtrl', function($scope) {
$scope.MyDate = Date("2014-09-23T15:26:49.1513672Z");
})
The date I'm working with is returned from the server as a string in the format shown above.
I've looked at the Angular documentation on date filters
<span>{{1288323623006 | date:'medium'}}</span><br>
and this outputs: Oct 28, 2010 8:40:23 PM
However, when I try to apply the same filter to $scope.MyDate like this:
{{MyDate | date:'medium'}}
the date doesn't format correctly but looks like this: Wed Sep 24 2014 07:40:02 GMT-0700 (Pacific Daylight Time)
Ultimately, I want to bind an input text box to this value and format it using the same filter:
<input type="text" class="form-control" ng-model="MyDatee | date:'medium'"/>
If I can get the basic version working, I hope to solve my actual problem with the text input.
Here's a helpful plunker link with the above code