Time displayed as GMT for IOS Devices

Time displayed as GMT for IOS Devices

CGARiggsCGARiggs Posts: 3Questions: 1Answers: 0

I have several Date/Time fields in my DataTable, where I render the date in the following format: "MM/DD/YY HH:MM AP" (i.e. 6/20/2018 3:38 PM).

        {
            "data": null,
            "visible": true,
            "render": function (data, type, full, meta) {
                return formatDate(data.arrival, false, 1);
            }
        },

This works, as expected, on all platforms, devices & browsers except IOS devices (used Safari & Chrome). We've used an iPad & iPhone (both IOS version 11.4), and the Date/Time is always represented as GMT.

FYI, I have Date/Time fields outside of the DataTables which appear correctly, so I'm assuming it's a combination of IOS and DataTables.

Is there something I'm missing or doing incorrectly?

Thank you

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Could you link to a page showing the issue please? Also, can you show us your formatDate() function since I guess the problem might be there.

    Allan

  • CGARiggsCGARiggs Posts: 3Questions: 1Answers: 0
    edited June 2018

    Thanks Allan!! The site, isn't currently ready for public consumption. When it's available and if this problem still exists, I'll gladly share it. In the meantime, here's the formatDate function:

    // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //  Function for Footer Date and Time
    //  iFormat:    1 - MM/DD/YY HH:MM AP
    //              2 - MM/DD/YYYY
    //              ELSE - DDDD MMM DD, YYYY HH:MM AP
    // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    function formatDate(sDate, bIncludeSecs, iFormat) {
        if (sDate == null) { return '';}
        var dDate = new Date(sDate);
        var hh = dDate.getHours();
        var sAMPM = " AM";
        var sHours = hh;
        if (sHours >= 12) {
            sHours = hh - 12;
            sAMPM = " PM";
        }
        if (sHours == 0) {
            sHours = 12;
        }
    
        var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
        var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    
        var sDateTime
    
        switch(iFormat) {
            case 1: //MM/DD/YY HH:MM AP
                if (bIncludeSecs)
                    sDateTime = (dDate.getMonth() + 1) + '/' + dDate.getDate() + '/' + dDate.getFullYear() + '  ' +
                        sHours + ':' + (dDate.getMinutes() < 10 ? '0' : '') + dDate.getMinutes() + ":" + (dDate.getSeconds() < 10 ? '0' : '') + dDate.getSeconds() + sAMPM;
                else
                    sDateTime = (dDate.getMonth() + 1) + '/' + dDate.getDate() + '/' + dDate.getFullYear() + '  ' +
                        sHours + ':' + (dDate.getMinutes() < 10 ? '0' : '') + dDate.getMinutes() + ' ' + sAMPM;
                break;
            case 2: //MM/DD/YYYY
                    sDateTime = (dDate.getMonth() + 1) + '/' + dDate.getDate() + '/' + dDate.getFullYear();
                break;
            default: //DDDD MMM DD, YYYY HH:MM AP
                if (bIncludeSecs)
                    sDateTime = days[dDate.getDay()] + ', ' + monthNames[dDate.getMonth()] + ' ' + dDate.getDate() + ", " + dDate.getFullYear() + "  " +
                        sHours + ":" + (dDate.getMinutes() < 10 ? '0' : '') + dDate.getMinutes() + ":" + (dDate.getSeconds() < 10 ? '0' : '') + dDate.getSeconds() + sAMPM;
                else
                    sDateTime = days[dDate.getDay()] + ', ' + monthNames[dDate.getMonth()] + ' ' + dDate.getDate() + ", " + dDate.getFullYear() + "  " +
                        sHours + ":" + (dDate.getMinutes() < 10 ? '0' : '') + dDate.getMinutes() + sAMPM;
        }
    
    
        return sDateTime;
    }
    
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Could you give me a sample of the sDate value you are giving the function and I'll see what happens when I run it locally?

    Thanks,
    Allan

  • CGARiggsCGARiggs Posts: 3Questions: 1Answers: 0

    It's a SQL smalldatetime value. One example value is "2018-06-19 12:26:00".

    Thanks again for you effort!!

This discussion has been closed.