iOS 7 mobile Safari no longer supports <input type=“datetime”/>

前端 未结 4 915
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 01:18

I have a rather large iPad application built using PhoneGap and I was doing some testing to make sure everything was going to work appropriately in

4条回答
  •  不思量自难忘°
    2020-12-17 01:56

    I ended up using the datetime-local but you have to make sure you take into account the timezone when binding to and from the control. We want to store GMT time in the database. I used the below functions to convert back and forth during binding.

    function formatHTML5DateTime(date)
    {
    try
    {
        if (typeof(date) == 'undefined' || date == null || date == '') return "";
    
        var tmpDate = new Date(date);
        // gets the timezone offset in minutes
        var offset = tmpDate.getTimezoneOffset();
        // apply the timezone offset in reverse to local time
        var newDate = tmpDate.addMinutes(Math.abs(offset) * -1);
    
        return newDate.toISOString().replace("Z", "");
    }
    catch(e)
    {
        return "";
    }
    }
    
    function formatJSDate(date)
    {
    try
    {
        if (typeof(date) == 'undefined' || date == null || date == '') return "";
    
        var tmpDate = new Date(date);
        // gets the timezone offset in minutes
        var offset = tmpDate.getTimezoneOffset();
        // apply the timezone offset to UTC time
        var newDate = tmpDate.addMinutes(offset);
    
        return newDate.toISOString();
    }
    catch(e)
    {
        return "";
    }
    }
    

提交回复
热议问题