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>
1

2 Answers 2

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();
  }
});
Sign up to request clarification or add additional context in comments.

2 Comments

How did you get the "1486218287000" value for 2017-02-04 19:54:47?
Perfect, exactly what was needed.
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"}}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.