Ibrahim Maher Ibrahim Maher - 4 years ago 101
AngularJS Question

Format datetime object in Array and display in ng-repeat AngularJS

I've a function that gets a list of Users. Each individual user has a

field which shows the last logged in time in this format
2017-02-04 19:54:47
. What I need to do is display that field on the page in this format
Saturday, February 2, 2017 - 19:54:47

Currently the time format is
2017-02-04 19:54:47
(native datetime format)
How can I format it such that it shows
Saturday, February 2, 2017 - 19:54:47

<th>Last Login</th>
<tr ng-repeat="user in users">
<td>{{ user.username }}</td>
<td>{{ user.last_login }}</td>

Answer Source

Try this

{{calculateTime(last_login) | date: 'EEEE, MMMM M, yyyy - HH:mm:ss'}}


app.controller('MainController', function($scope) {
  $scope.last_login = "2017-02-04 19:54:47";
  $scope.calculateTime = function(dt) {
    return new Date(dt).getTime();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download