Docs    Facebook    Customizations

Change Dates to Relative “Time Ago” Time

This snippet will move the date/time the post was made to display underneath the caption in relative time.

if (!Date.now) {
    Date.now = function() { return new Date().getTime(); }
}
var sbiDateIcon = '<svg class="svg-inline--fa fa-clock fa-w-16" aria-hidden="true" data-fa-processed="" data-prefix="far" data-icon="clock" role="presentation" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200zm61.8-104.4l-84.9-61.7c-3.1-2.3-4.9-5.9-4.9-9.7V116c0-6.6 5.4-12 12-12h32c6.6 0 12 5.4 12 12v141.7l66.8 48.6c5.4 3.9 6.5 11.4 2.6 16.8L334.6 349c-3.9 5.3-11.4 6.5-16.8 2.6z">';
jQuery('.sbi_item').each(function() {
    var difference = (Date.now()/1000)-parseInt(jQuery(this).attr('data-date'));
    if(difference < (60*60)) {
        jQuery(this).find('.sbi_date').html(sbiDateIcon + ' less than 1 hour ago');
    } else if(difference < (60*60*2)) {
        jQuery(this).find('.sbi_date').html(sbiDateIcon + ' 1 hour ago');
    } else if(difference < (60*60*24)) {
        jQuery(this).find('.sbi_date').html(sbiDateIcon + ''+Math.floor((difference/(60*60)))+' hours ago');
    } else if(difference < (60*60*24*2)) {
        jQuery(this).find('.sbi_date').html(sbiDateIcon + ' 1 day ago');
    } else if(difference < (60*60*24*7)) {
        jQuery(this).find('.sbi_date').html(sbiDateIcon + ''+Math.floor((difference/(60*60*24)))+' days ago');
    } else if(difference < (60*60*24*7*2)) {
        jQuery(this).find('.sbi_date').html(sbiDateIcon + ' 1 week ago');
    } else {
        jQuery(this).find('.sbi_date').html(sbiDateIcon + ''+Math.floor((difference/(60*60*24*7)))+' weeks ago');
    }
});

German Translation

if (!Date.now) {
    Date.now = function() { return new Date().getTime(); }
}
var sbiDateIcon = '<svg class="svg-inline--fa fa-clock fa-w-16" aria-hidden="true" data-fa-processed="" data-prefix="far" data-icon="clock" role="presentation" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200zm61.8-104.4l-84.9-61.7c-3.1-2.3-4.9-5.9-4.9-9.7V116c0-6.6 5.4-12 12-12h32c6.6 0 12 5.4 12 12v141.7l66.8 48.6c5.4 3.9 6.5 11.4 2.6 16.8L334.6 349c-3.9 5.3-11.4 6.5-16.8 2.6z"></path></svg>';
jQuery('.sbi_item').each(function() {
    var difference = (Date.now()/1000)-parseInt(jQuery(this).attr('data-date'));
    if(difference < (60*60)) {
        jQuery(this).find('.sbi_date').html(sbiDateIcon + ' weniger als 1 Stunde');
    } else if(difference < (60*60*2)) {
        jQuery(this).find('.sbi_date').html(sbiDateIcon + ' vor 1 Stunde');
    } else if(difference < (60*60*24)) {
        jQuery(this).find('.sbi_date').html(sbiDateIcon + 'vor ' + ''+Math.floor((difference/(60*60)))+' Stunden');
    } else if(difference < (60*60*24*2)) {
        jQuery(this).find('.sbi_date').html(sbiDateIcon + 'vor einem 1 Tag');
    } else if(difference < (60*60*24*7)) {
        jQuery(this).find('.sbi_date').html(sbiDateIcon + 'vor ' + ''+Math.floor((difference/(60*60*24)))+' Tagen');
    } else if(difference < (60*60*24*7*2)) {
        jQuery(this).find('.sbi_date').html(sbiDateIcon + ' vor 1 Woche');
    } else {
        jQuery(this).find('.sbi_date').html(sbiDateIcon + 'vor ' + ''+Math.floor((difference/(60*60*24*7)))+' Wochen');
    }
});
support

Couldn’t find your answer in the docs?

Contact Support

Was this article helpful?