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

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

I tried this:

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

H

10条回答
  •  Happy的楠姐
    2020-12-25 12:27

    When submitting

    using

    the value format you will get is look like this.

    2019-09-06T00:21

    To set new value in your input type box.

    You must use:

    date('Y-m-d\TH:i', strtotime($exampleDate)) //2019-08-18T00:00
    

    Solution Example:

    $exampleDate = "2019-08-18 00:00:00";//sql timestamp
    $exampleDate = strtotime($exampleDate);
    $newDate = date('Y-m-d\TH:i', $exampleDate);
    

    or

    $exampleDate = "2019-08-18 00:00:00";//sql timestamp
    $newDate = date('Y-m-d\TH:i', strtotime($exampleDate));
    

    If you dont use strtotime() you will get an error of

    Notice: A non well formed numeric value encountered


    Tested:

     - $exampleDate = 2019-08-18 00:00:00 ;
     - //Not Working - output(1970-01-01T01:33:39)
     - 
     - //Not Working - output(1970-01-01T01:33:39+01:00)
     - 
     - //Not Working - output(2019-08-18T00:00:00+02:00)
     - 
     - //Not Working - output(2019-09-23T19:36:01+02:00)
     - format('c');?>
     - //Working Perfect - output(2019-08-18T00:00:00)
     -  
    

提交回复
热议问题