Input type DateTime - Value format?

后端 未结 7 823
长发绾君心
长发绾君心 2020-11-27 18:10

In which format should I put the date and time, for use in the HTML5 input element with datetime type?

I have tried:

  • 1338575502
7条回答
  •  天命终不由人
    2020-11-27 18:18

    This was a good waste of an hour of my time. For you eager beavers, the following format worked for me:

    
    

    The spec was a little confusing to me, it said to use RFC 3339, but on my PHP server when I used the format DATE_RFC3339 it wasn't initializing my hmtl input :( PHP's constant for DATE_RFC3339 is "Y-m-d\TH:i:sP" at the time of writing, it makes sense that you should get rid of the timezone info (we're using datetime-LOCAL, folks). So the format that worked for me was:

    "Y-m-d\TH:i:s"
    

    I would've thought it more intuitive to be able to set the value of the datepicker as the datepicker displays the date, but I'm guessing the way it is displayed differs across browsers.

提交回复
热议问题