I have an api returning timestamp variable. When I print in AngularJs it shows as 1488195848000.But I want that to be displayed as 2017-02-28 14:49:48(In Timestamp format)
How do I convert in controller?
I have an api returning timestamp variable. When I print in AngularJs it shows as 1488195848000.But I want that to be displayed as 2017-02-28 14:49:48(In Timestamp format)
How do I convert in controller?
If you want to convert that variable in HTML,
{{variable | date : 'yyyy-MM-dd HH:mm:ss'}}
And in case of JS,
$filter('date')(variable, 'yyyy-MM-dd HH:mm:ss')
Note: In case of JS, do not forget to add $filter as dependency.
You can format date in AngularJS using the pipe operator and the date filter
<span>{{1488195848000| date:'yyyy-MM-dd HH:mm:ss'}}</span>
In the controller you need to make use of filter function to format the date like
var _date = $filter('date')(_date, 'yyyy-MM-dd HH:mm:ss')