0

I've a function that gets a list of Users. Each individual user has a last_logged 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

<table>
  <thead>
    <tr>
      <th>Username</th>
      <th>Last Login</th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="user in users">
      <td>{{ user.username }}</td>
      <td>{{ user.last_login }}</td>
    </tr>
  </tbody>
</table>
lin
  • 17,956
  • 4
  • 59
  • 83
  • Possible duplicate of [How to format date in angularjs](http://stackoverflow.com/questions/22392328/how-to-format-date-in-angularjs) – lin Feb 04 '17 at 17:54

2 Answers2

1

Try this

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

Demo

app.controller('MainController', function($scope) {
  $scope.last_login = "2017-02-04 19:54:47";
  $scope.calculateTime = function(dt) {
    return new Date(dt).getTime();
  }
});
Nagarjuna Reddy
  • 4,083
  • 14
  • 41
  • 85
0

You can format a date with the date filter and the format that you need to get that its

date:"EEEE',' MMMM d',' yyyy ' - ' HH:mm"

so you code would look like something like this

{{user.last_login  | date:"EEEE',' MMMM d',' yyyy ' - ' HH:mm"}}
Juan
  • 4,910
  • 3
  • 37
  • 46