Time ago JS

Time ago JS

by Gopinath Kaliappan

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/timeago.js/2.0.4/timeago.min.js"></script>
<span class="rfnb_date">Publié: December 11, 2016 - 19:09 pm</span>
<br>
<span class="rfnb_date" datetime="2020-02-02T10:13:07-0500">July 07, 2016</span>
<br>
<span class="rfnb_date" datetime="2016-12-12 02:11:13">Publié: December 11, 2016 - 19:09 pm</span>

JavaScript

// http://timeago.org/
new timeago().render(document.querySelectorAll('.rfnb_date'));
// or use jquery selector
//new timeago().render($('.rfnb_date'));

// LANGUE

var locale = function(number, index) {
  // number: the timeago / timein number;
  // index: the index of array below;
  return [
    ['just now', 'right now'],
    ['%s seconds ago', 'in %s seconds'],
    ['1 minute ago', 'in 1 minute'],
    ['%s minutes ago', 'in %s minutes'],
    ['1 hour ago', 'in 1 hour'],
    ['%s hours ago', 'in %s hours'],
    ['1 day ago', 'in 1 day'],
    ['%s days ago', 'in %s days'],
    ['1 week ago', 'in 1 week'],
    ['%s weeks ago', 'in %s weeks'],
    ['1 month ago', 'in 1 month'],
    ['%s months ago', 'in %s months'],
    ['1 year ago', 'in 1 year'],
    ['%s years ago', 'in %s years']
  ][index];
};
timeago.register('pt_BR', locale);
var timeagoInstance = timeago();
// then you can use it
timeagoInstance.format(1473245023718, 'pt_BR');