• 07-12-2020, 17:06:24
    #1
    Arkadaşlar merhaba, kullanmak istediğim bir kod var lakin kodu ingilizce düzenlemişler sorun değil türkçeleştirdim fakat Eş Güdümlü Evrensel Zaman (UTC) tarih formatına göre düzenlenmiş kod, haliyle türkçe blogumun dili türkçe olduğu için çalışmıyor, ingilizce yaptığımda çalışıyor, bu kodu türkiye saat dilimi olan GMT zaman dilimine nasıl çevirebilirim?

    (function timeAgo(selector) {
        var templates = {
            prefix: "",
            suffix: " önce",
            seconds: "Birkaç saniye",
            minute: "yaklaşık bir dakika",
            minutes: "%d dakika",
            hour: "yaklaşık bir saat",
            hours: "%d saat",
            day: "bir gün",
            days: "%d gün",
            month: "yaklaşık bir ay",
            months: "%d ay",
            year: "bir yıl",
            years: "%d yıl"
        };
        var template = function(t, n) {
            return templates[t] && templates[t].replace(/%d/i, Math.abs(Math.round(n)));
        };
        var timer = function(time) {
            if (!time) return;
            time = time.replace(/\.\d+/, "");
            time = time.replace(/-/, "/").replace(/-/, "/");
            time = time.replace(/T/, " ").replace(/Z/, " UTC");
            time = time.replace(/([\+\-]\d\d)\:?(\d\d)/, " $1$2");
            time = new Date(time * 1000 || time);
            var now = new Date();
            var seconds = ((now.getTime() - time) * .001) >> 0;
            var minutes = seconds / 60;
            var hours = minutes / 60;
            var days = hours / 24;
            var years = days / 365;
            return templates.prefix + (seconds < 45 && template('seconds', seconds) || seconds < 90 && template('minute', 1) || minutes < 45 && template('minutes', minutes) || minutes < 90 && template('hour', 1) || hours < 24 && template('hours', hours) || hours < 42 && template('day', 1) || days < 30 && template('days', days) || days < 45 && template('month', 1) || days < 365 && template('months', days / 30) || years < 1.5 && template('year', 1) || template('years', years)) + templates.suffix;
        };
        var elements = document.getElementsByClassName('datetime');
        for (var i in elements) {
            var $this = elements[i];
            if (typeof $this === 'object') {
                $this.innerHTML = timer($this.getAttribute('title') || $this.getAttribute('data-datetime'));
            }
        }
        setTimeout(timeAgo, 60000);
    })();
  • 07-12-2020, 17:08:49
    #2
    Datetime +3 hours eklemen yeterli
  • 07-12-2020, 17:09:23
    #3
    voyager adlı üyeden alıntı: mesajı görüntüle
    Datetime +3 hours eklemen yeterli
    Nereye eklemeliyim hocam gösterir misiniz? Lakin Hala UTC zaman diliminde kalacak kod, bu kadar basit olacağını zannetmiyorum.
  • 07-12-2020, 17:12:29
    #4
    iGurler adlı üyeden alıntı: mesajı görüntüle
    Nereye eklemeliyim hocam gösterir misiniz? Lakin Hala UTC zaman diliminde kalacak kod, bu kadar basit olacağını zannetmiyorum.
    Date.prototype.addHours = function(h) { this.setTime(this.getTime() + (h*60*60*1000)); return this; }

    Bu property i öncesinde eklemen gerekli sonrasında ise,
    var now = new Date().addHours(3) yapabilirsin
  • 07-12-2020, 17:26:29
    #5
    (function timeAgo(selector) {   Date.prototype.addHours = function(h) { this.setTime(this.getTime() + (h*60*60*1000)); return this; }    var templates = {        prefix: "",        suffix: " önce",        seconds: "Birkaç saniye",        minute: "yaklaşık bir dakika",        minutes: "%d dakika",        hour: "yaklaşık bir saat",        hours: "%d saat",        day: "bir gün",        days: "%d gün",        month: "yaklaşık bir ay",        months: "%d ay",        year: "bir yıl",        years: "%d yıl"    };    var template = function(t, n) {        return templates[t] && templates[t].replace(/%d/i, Math.abs(Math.round(n)));    };    var timer = function(time) {        if (!time) return;        time = time.replace(/\.\d+/, "");        time = time.replace(/-/, "/").replace(/-/, "/");        time = time.replace(/T/, " ").replace(/Z/, " UTC");        time = time.replace(/([\+\-]\d\d)\:?(\d\d)/, " $1$2");        time = new Date(time * 1000 || time);        var now = new Date().addHours(3)        var seconds = ((now.getTime() - time) * .001) >> 0;        var minutes = seconds / 60;        var hours = minutes / 60;        var days = hours / 24;        var years = days / 365;        return templates.prefix + (seconds < 45 && template('seconds', seconds) || seconds < 90 && template('minute', 1) || minutes < 45 && template('minutes', minutes) || minutes < 90 && template('hour', 1) || hours < 24 && template('hours', hours) || hours < 42 && template('day', 1) || days < 30 && template('days', days) || days < 45 && template('month', 1) || days < 365 && template('months', days / 30) || years < 1.5 && template('year', 1) || template('years', years)) + templates.suffix;    };    var elements = document.getElementsByClassName('datetime');    for (var i in elements) {        var $this = elements[i];        if (typeof $this === 'object') {            $this.innerHTML = timer($this.getAttribute('title') || $this.getAttribute('data-datetime'));        }    }    setTimeout(timeAgo, 60000); })();
  • 07-12-2020, 17:31:44
    #6
    voyager adlı üyeden alıntı: mesajı görüntüle
    (function timeAgo(selector) {   Date.prototype.addHours = function(h) { this.setTime(this.getTime() + (h*60*60*1000)); return this; }    var templates = {        prefix: "",        suffix: " önce",        seconds: "Birkaç saniye",        minute: "yaklaşık bir dakika",        minutes: "%d dakika",        hour: "yaklaşık bir saat",        hours: "%d saat",        day: "bir gün",        days: "%d gün",        month: "yaklaşık bir ay",        months: "%d ay",        year: "bir yıl",        years: "%d yıl"    };    var template = function(t, n) {        return templates[t] && templates[t].replace(/%d/i, Math.abs(Math.round(n)));    };    var timer = function(time) {        if (!time) return;        time = time.replace(/\.\d+/, "");        time = time.replace(/-/, "/").replace(/-/, "/");        time = time.replace(/T/, " ").replace(/Z/, " UTC");        time = time.replace(/([\+\-]\d\d)\:?(\d\d)/, " $1$2");        time = new Date(time * 1000 || time);        var now = new Date().addHours(3)        var seconds = ((now.getTime() - time) * .001) >> 0;        var minutes = seconds / 60;        var hours = minutes / 60;        var days = hours / 24;        var years = days / 365;        return templates.prefix + (seconds < 45 && template('seconds', seconds) || seconds < 90 && template('minute', 1) || minutes < 45 && template('minutes', minutes) || minutes < 90 && template('hour', 1) || hours < 24 && template('hours', hours) || hours < 42 && template('day', 1) || days < 30 && template('days', days) || days < 45 && template('month', 1) || days < 365 && template('months', days / 30) || years < 1.5 && template('year', 1) || template('years', years)) + templates.suffix;    };    var elements = document.getElementsByClassName('datetime');    for (var i in elements) {        var $this = elements[i];        if (typeof $this === 'object') {            $this.innerHTML = timer($this.getAttribute('title') || $this.getAttribute('data-datetime'));        }    }    setTimeout(timeAgo, 60000); })();
    Malesef bu sefer kod tamamen bozuldu çalışmıyor hocam.
  • 07-12-2020, 17:41:51
    #7
    iGurler adlı üyeden alıntı: mesajı görüntüle
    Malesef bu sefer kod tamamen bozuldu çalışmıyor hocam.
    https://jsfiddle.net/voyager_26/qf9wjLek/1/

    Al yaptım. Alerte dikkat et değere bak
  • 07-12-2020, 17:52:48
    #8
    Çözüldü mü kardeşim?
  • 07-12-2020, 17:54:41
    #9
    voyager adlı üyeden alıntı: mesajı görüntüle
    Çözüldü mü kardeşim?
    Hayır hocam bakın,

        var timer = function(time) {
            if (!time) return;
            time = time.replace(/\.\d+/, "");
            time = time.replace(/-/, "/").replace(/-/, "/");
            time = time.replace(/T/, " ").replace(/Z/, " UTC");
            time = time.replace(/([\+\-]\d\d)\:?(\d\d)/, "
    Bu kısım yine utc zaman dilimini baz alıyor ve blog dili türkçe olduğu zaman yani türkçe saat dilimi olduğunda çalışmıyor, resimdende anlayabilirsiniz, blog dilini ingilizce yaptığımda zaten doğru gösteriyor onda sorun yok, benim anlamadığım türkçe diline çevirdiğimde kod çalışmıyor.