The forum of the forums

Would you like to react to this message? Create an account in a few clicks or log in to continue.
The forum of the forums
2 posters

    Time date format [time ago] not displayed week, month and year ago

    avatar
    dang02315
    New Member


    Male Posts : 8
    Reputation : 1
    Language : Vietnamese

    Time date format [time ago] not displayed week, month and year ago Empty Time date format [time ago] not displayed week, month and year ago

    Post by dang02315 Wed 14 Mar - 15:30

    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:

    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.
    avatar
    dang02315
    New Member


    Male Posts : 8
    Reputation : 1
    Language : Vietnamese

    Time date format [time ago] not displayed week, month and year ago Empty Re: Time date format [time ago] not displayed week, month and year ago

    Post by dang02315 Thu 15 Mar - 7:20

    Please help me
    Wecoc
    Wecoc
    Forumember


    Male Posts : 144
    Reputation : 111
    Language : Catalan, Spanish, English

    Time date format [time ago] not displayed week, month and year ago Empty Re: Time date format [time ago] not displayed week, month and year ago

    Post by Wecoc Sun 18 Mar - 16:26

    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.

      Current date/time is Mon 11 Nov - 17:48