javascript - Custom formatting for a time using Moment.js -


i'm having difficulty formatting time using moment.js. decided try out angular-moment , faced limitations, , after looking @ documentation moment.js, seems lot better create custom directive uses moment. here lies problem, have experience , knowledge of basic directives, i'm not sure how move forward creating directive uses moment format date/time. so, here rules want adhere to:

less 1 minute ago: print a few seconds ago more 1 minute ago && less 1 hour ago: print x minutes ago more 1 hour ago: print h:mm a yesterday (this should compare 2 days see if today or yesterday): print yesterday more yesterday: print mmm dd

so i'm unsure start really, , welcome!

moment.js way go! recommend use angular filter instead of directive.

here how might implement 1 moment.js fromnow function:

var fromnow = function () {         return function (value, format) {             return moment(value).fromnow();         };     };      angular.module('myapp').filter('fromnow', fromnow); 

and call html:

<span>{{player.activesince | fromnow}}</span> 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -