HTML 5 - Input type date formatting on iOS

后端 未结 4 711
一生所求
一生所求 2021-01-06 03:30

I am using an HTML 5 form on an iPhone. This form has an input element like the following:


W

相关标签:
4条回答
  • 2021-01-06 03:47

    The following should do it.

    $dat = new DateTime($_POST['MyDATE']);
    $new_format = $dat->format('Y-m-d');
    
    0 讨论(0)
  • 2021-01-06 04:03

    No.

    There are two formats at play:

    • displayed format
    • internal format exposed to JavaScript and sent to the server

    You cannot change the display format. It's up to the browser to decide how the date is presented to the user (in practice it's determined by system's locale).

    You cannot change the internal format either. It's always ISO8601, regardless of browser/locale.

    0 讨论(0)
  • 2021-01-06 04:05

    I always thought the format was meant to be YYYY-MM-DD.

    W3C spec & RFC3339.

    Anyway, you could convert it with JavaScript.

    var dateInput = document.getElementById('birthdate');
    
    dateInput.addEventListener('change', function() {
        dateInput.value = new Date(dateInput.value).toISOString().split('T')[0];
    }, false);
    
    0 讨论(0)
  • 2021-01-06 04:08

    I agree with @PorneL's answer, however, you can potentially do some work to simulate the results you want. I will stipulate that it's not the best way to do it.

    In pseudo code:

    • Have two inputs, one of type date and another of text.
    • Make the date input either invisible or 1px x 1px in side, and make the input the size that of the date that you would like
    • On focus on the text input, set focus on the adjacent date input automatically.
    • At this point, the user will be editing the date input field
    • On change of the date field, grab the value and insert it into the text field using whatever formatting you prefer.

    Again, it may not be the best solution, but it can work this way.

    0 讨论(0)
提交回复
热议问题