-
-
Notifications
You must be signed in to change notification settings - Fork 708
Ryan McGeary edited this page Jun 26, 2015
·
7 revisions
Q: How would I make the months and years just show the number days? For example instead of it saying 2 months, it would say 55 days.
A: The only way to do this with timeago is to completely override the locale settings for month
, months
, year
, and years
with a custom function. Here's an example:
var daysOnly = function(value, distanceMillis) {
var days = Math.abs(distanceMillis) / 1000 / 60 / 60 / 24;
return Math.round(days) + " days";
}
$.timeago.settings.strings.month = daysOnly;
$.timeago.settings.strings.months = daysOnly;
$.timeago.settings.strings.year = daysOnly;
$.timeago.settings.strings.years = daysOnly;
$(document).ready(function() {
$("time.timeago").timeago();
}
Aside: The Russian locale shows what's possible with more advanced custom locale functions.