Display datetime like 1 hour ago, 5 hours ago - Angularjs -


i display last login time on control panel. how display datetime this:

1 hour ago,  5 hours ago 

moment.js great way this. i've set plunkr shows basic example on how this.

http://plnkr.co/edit/64mfpdhuxdxcqo6r8xrf?p=preview

to summarise, can use .fromnow() method display difference between date , current time:

$scope.difference = moment($scope.yourdate).fromnow(); 

if $scope.yourdate 1 hour ago, $scope.difference set an hour ago.

edit

based on comment, i've update plunker use date you've provided.

$scope.yourdate = new date('2015-07-08t14:02:42.973'); $scope.difference = moment($scope.yourdate).fromnow(); 

at time of writing, sets $scope.difference 20 hours ago.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -