How do I properly display the date and time in AngularJS?
The output below shows both the input and the output, with and without the AngularJS date filter:
we can format the date on view side in angular is very easy....please check the below example:
{{dt | date : "dd-MM-yyyy"}}
Have you seen the Writing directives (short version) section of the documentation?
HTML
<div ng-controller="Ctrl2">
Date format: <input ng-model="format"> <hr/>
Current time is: <span my-current-time="format"></span>
</div>
JS
function Ctrl2($scope) {
$scope.format = 'M/d/yy h:mm:ss a';
}
v.Dt is likely not a Date() object.
See http://jsfiddle.net/southerd/xG2t8/
but in your controller:
scope.v.Dt = Date.parse(scope.v.Dt);
you can get the 'date' filter like this:
var today = $filter('date')(new Date(),'yyyy-MM-dd HH:mm:ss Z');
This will give you today's date in format you want.
Inside a controller the format can be filtered by injecting $filter.
var date = $filter('date')(new Date(),'MMM dd, yyyy');
Here are a few popular examples:
<div>{{myDate | date:'M/d/yyyy'}}</div>
7/4/2014
<div>{{myDate | date:'yyyy-MM-dd'}}</div>
2014-07-04
<div>{{myDate | date:'M/d/yyyy HH:mm:ss'}}</div>
7/4/2014 12:01:59