My date format:
- Today at 12:00
- Yesterday at 12:00
- 01.01.18 12:00
- on 01.01.18 12:00
The code I'm using:
I need to add week, month and years ago. Please help me, thanks.
- Today at 12:00
- Yesterday at 12:00
- 01.01.18 12:00
- on 01.01.18 12:00
The code I'm using:
- Code:
$(function() {
var x = $('.timez');
for (i = 0; i < x.length; i++) {
x[i].innerHTML = x[i].innerHTML.replace('on', '')
};
(function(g) {
function e(a) {
var c = (new Date).getHours();
a = parseInt(((new Date).getTime() - (new Date(a)).getTime()) / 6E4);
var b = parseInt(a / 60);
if (0 === b) return a + " minute ago";
if (b <= c) return b + " second ago";
if (b > c && b < c + 24) return b + " hours ago";
if (b > c + 24) return parseInt((b - c) / 24) + 1 + " day ago"
}
g(".timez").text(function() {
var a = this.textContent.trim();
if (/^(Yester|To)day\sat\s\d{1,2}:\d{2,2}$/.test(a)) {
var c = a.match(/\s(\d{1,2})\:(\d{2,2})$/),
b = new Date,
d = new Date(b),
f = function(a) {
var b = a.getDate(),
d = a.getMonth();
a = a.getFullYear();
return e(new Date(a, d, b, c[1], c[2]))
};
d.setDate(b.getDate() - 1);
return -1 !== a.indexOf("Today") ? f(b) : f(d)
}
if (/^\d{2,2}\.\d{2,2}\.\d{2,2}\s\d{1,2}:\d{2,2}$/.test(a)) return a = a.split(/\W/), a = new Date("20" + a[2], parseInt(a[1], 10) - 1, a[0], a[3], a[4]), e(a)
})
})(jQuery);
});
I need to add week, month and years ago. Please help me, thanks.