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

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

I tried this:

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

H

相关标签:
10条回答
  • 2020-12-25 12:36

    Try it:

    <input type="datetime-local"  value="<?php $row['Time'] = preg_replace("/\s/",'T',$row['Time']); echo $row['Time']?>" class="date" name="start" REQUIRED>
    

    0 讨论(0)
  • 2020-12-25 12:40

    This will convert datetime from database to datetime-local

    str_replace(" ","T",substr_replace($string ,"", -3))

    0 讨论(0)
  • 2020-12-25 12:42

    None of the above solutions worked for me as of 2019 using Google Chrome Version 78.0.3904.70 (Official Build) (64-bit)

    What worked for me is.

    <input type="datetime-local" value="2017-06-13T13:00">
    

    As you can see the format is 2017-06-13T13:00 or Y-m-dTH:i.

    As of PHP you can do like.

    <input type="datetime-local" value="<?php echo Date('Y-m-d\TH:i',time()) ?>">
    

    Hope this will save someone's time. :)

    0 讨论(0)
  • 2020-12-25 12:42

    Better use timezone feature

    function getCurrentDateTime(){
        $date = new DateTime();
        $date->setTimezone(new DateTimeZone('GMT+6')); //Time Zone GMT +6
        $dt= $date->format('Y-m-d\TH:i:s');
        return $dt;
    }
    
    0 讨论(0)
提交回复
热议问题