Announcement

Collapse
No announcement yet.

using Intl.DateTimeFormat ( java script ) in vbulletin

Collapse
X
Collapse
First Prev Next Last
 
  • Filter
  • Time
  • Show
Clear All
new posts

    using Intl.DateTimeFormat ( java script ) in vbulletin

    Hello my friend

    how can use Intl.DateTimeFormat java script method for using in vbulletin? for changing the time?

    it is here:

    Intl.DateTimeFormat - JavaScript | MDN
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat



    what is the right code can put into style?​

    #2
    What exactly do you want to do? If you have different languages on your forum, you can specify the date formats for each language in the Language Manager in AdminCP. All the dates on the site will automatically use that date format from the backend. No JS needed.

    Comment


      #3
      tnx
      in our language we are not using gregorian date we are using shamsi date.

      shamsi date is not in vbulletin so we should convert gregorian to shamsi. i try before in php but i could not. now i am trying with front end with java script. tnx

      Comment


        #4
        tnx i try before in php for changing time and i could not.

        i try to do that with this code and most of date are changed in front end

        Code:
        function gregorian_to_jalali(gy, gm, gd) {
            var g_d_m, jy, jm, jd, gy2, days;
            g_d_m = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
            gy2 = (gm > 2) ? (gy + 1) : gy;
            days = 355666 + (365 * gy) + ~~((gy2 + 3) / 4) - ~~((gy2 + 99) / 100) + ~~((gy2 + 399) / 400) + gd + g_d_m[gm - 1];
            jy = -1595 + (33 * ~~(days / 12053));
            days %= 12053;
            jy += 4 * ~~(days / 1461);
            days %= 1461;
            if (days > 365) {
                jy += ~~((days - 1) / 365);
                days = (days - 1) % 365;
            }
            if (days < 186) {
                jm = 1 + ~~(days / 31);
                jd = 1 + (days % 31);
            } else {
                jm = 7 + ~~((days - 186) / 30);
                jd = 1 + ((days - 186) % 30);
            }
            return [jy, jm, jd];
        }
        
        chng_date = () => {
        
            var elms = document.getElementsByTagName("*"),
                len = elms.length,
                reg = /\d{1,4} \d{1,2} \d{1,2}, \d{1,2}:\d{1,2}|\d{1,2}:\d{1,2} \d{1,4} \d{1,4} \d{1,4}/gi;
            for (var ii = 0; ii < len; ii++) {
                var myChildred = elms[ii].childNodes;
                len2 = myChildred.length;
                for (var jj = 0; jj < len2; jj++) {
                    if (myChildred[jj].nodeType === 3) {
                        // example on update a text node's value
                        if (reg.test(myChildred[jj].nodeValue)) {
                            //                 a = myChildred[jj].nodeValue.split(',')[0].split(' ');
                            a = myChildred[jj].nodeValue.slice([myChildred[jj].nodeValue.search(reg)]).split(' ')
                            a = (/\d{2}:\d{2}/.test(a[0])) ? a.splice(1, 4) : a
                            y = gregorian_to_jalali(Number(a[0]), Number((a[1][0] == '0') ? a[1][1] : a[1]), Number((a[2][0] == '0') ? a[2][1] : a[2][0] + a[2][1]));
                            myChildred[jj].nodeValue = myChildred[jj].nodeValue.replace(reg, y);
        
                        }
        
                    }
                }
            }
        }
        chng_date();
        
        $(document).click(function() {
            console.log('ok')
            chng_date();
        
            w = 0
        
            a = setInterval(function() {
                chng_date()
                if (w == 3) {
                    clearInterval(a)
                }
            }, 800)
        
            setTimeout(function() {
                console.log('s');
            }, 1000);
        
        });​
        
        
        ​
        now i found Intl.DateTimeFormat java script method​ that is very simpler than my above code.​

        Comment


          #5
          All the dates displayed on multiple parts of the pages are generated on the backend in PHP. Changing them on the frontend is not recommended and not efficient. Plus search engines may not pick up the altered date format because it was modified using JS. And with your JS code, for every mouse click, it looks up the dates to modify from the HTML nodes on every page, which contains thousands of nodes. That may freeze the page due to these extensive operations.

          I recommend setting the date format on the backend using PHP.

          Comment

          Latest Posts

          Collapse

          Working...
          X
          Searching...Please wait.
          An unexpected error was returned: 'Your submission could not be processed because you have logged in since the previous page was loaded.

          Please push the back button and reload the previous window.'
          An unexpected error was returned: 'Your submission could not be processed because the token has expired.

          Please push the back button and reload the previous window.'
          An internal error has occurred and the module cannot be displayed.
          There are no results that meet this criteria.
          Search Result for "|||"