How do I Display Dates in jquery.timeago format for last 24 hours else show short month name
question says it all i think. 开发者_Python百科 i'm not that great with js, been trying for a while. thanks.
New Answer
It appears that I may have misunderstood the functionality of the jQuery plugin when previously answering. It appears to me, that the best way to get the functionality you want will be to modify the jQuery plugin. Modifying the plugin won't be a simple task but if you really need said functionality it may be worth it.
Old Answer
The strings returned from the jQuery.timeago plugin will always return a string containing
- minute
- minutes
- hour
- hours
if it is within the current 24 hour period.
In JavaScript, check the returned string with a regex to see if it is within 24 hours and if it isn't, use the date object to get the month.
Example regex test:
hours?|minutes?
Example test:
var now = $.timeago(new Date());
console.log(now);
console.log( /hours|hour|minutes|minute/g.test(now) );
Example console output:
This should be enough to get you headed in the right direction.
精彩评论