AngularJS. Convert tag value (Unix time to human-readable time)

I have faced the issue with unix time formatted as a number of seconds from the epoch start or as a number of milliseconds that is used in JavaScript. So strictly speaking, AngularJS doesn't convert Unix timestamp to Date, but a number with milliseconds, which is 1000 times larger, so first you will have to multiply your input number by 1000, like this:

<mydate>{{item.date * 1000 | date:'yyyy-MM-dd HH:mm:ss Z'}}</mydate>

Otherwise your date will be wrong.


Use format date filter like this:

<mydate>{{item.date * 1000 | date:'yyyy-MM-dd HH:mm:ss Z'}}</mydate>

Reference


If you have a Unix timestamp, you'll probably have to multiply your timestamp by 1000 since the Unix timestamp is in seconds and AngularJs date filter needs milliseconds.

vm.milliseconds = Date('1441981121' * 1000);

then use $filter() function

var date = $filter('date')(vm.milliseconds, 'd MMMM yyyy');

or you can use in ng-bind

<span ng-bind="myController.milliseconds | date : 'd MMMM yyyy'"></span>