Time date format [time ago] not displayed week, month and year ago
2 posters
Page 1 of 1
Time date format [time ago] not displayed week, month and year ago
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.
Re: Time date format [time ago] not displayed week, month and year ago
If I understood, you are trying to set a custom date format using the one already displayed in the forum, am I right?
The problem is every user can set their preferred date format in the profile, so your code would not work in all them, only in the one you had...
Also I don't see the reason to do that, there are many date formats available in the profile.
To change it go to Profile Preferences Date format
Sorry if I misunderstood, please explain better what you are trying to accomplish.
The problem is every user can set their preferred date format in the profile, so your code would not work in all them, only in the one you had...
Also I don't see the reason to do that, there are many date formats available in the profile.
To change it go to Profile Preferences Date format
Sorry if I misunderstood, please explain better what you are trying to accomplish.
Wecoc- Forumember
- Posts : 144
Reputation : 111
Language : Catalan, Spanish, English
Similar topics
» How do I change the time format?
» Date & Time
» Changing the military time format
» Wrong time displayed in the messages
» Date and time
» Date & Time
» Changing the military time format
» Wrong time displayed in the messages
» Date and time
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum