How to set a value for the input type 'datetime-local'?

后端 未结 10 1277
猫巷女王i
猫巷女王i 2020-12-25 11:59

I tried this:

\" class=\"date\" name=\"start\" REQUIRED>

H

10条回答
  •  轮回少年
    2020-12-25 12:16

    I don't know exacly what is in $row['Time'] but it should be as follows:

    Definition

    A valid date-time as defined in RFC 3339 with these additional qualifications:

    • the literal letters T and Z in the date/time syntax must always be uppercase
    • the date-fullyear production is instead defined as four or more digits representing a number greater than 0

    Examples

    • 1990-12-31T23:59:60Z
    • 1996-12-19T16:39:57-08:00

    Solution

    To create RFC 3339 format in PHP you can use:

    echo date('Y-m-d\TH:i:sP', $row['Time']);
    

    or in another way:

    echo date("c", strtotime($row['Time']));  
    

    or if you prefer objective style:

    echo (new DateTime($row['Time']))->format('c');
    

    In your code

    So in your code it would look as follows:

    
    

    or

    " class="date" name="start" REQUIRED>
    

    Manual

    • More informations can be found here

    • PHP date Manual

    • PHP DateTime Manual

提交回复
热议问题