1. 程式人生 > >input datetime-local 設定預設值

input datetime-local 設定預設值

<div class="form-group">
  <label for="start_time" class="col-xs-4 col-sm-2 control-label"><span style="color:red;">*&nbsp;</span>起始時間&nbsp;:</label>
  <div class="col-xs-8 col-sm-9 form-inline">
    <input type="datetime-local" name="start_time" class="form-control"
value="
{{old('start_time',$data->start_time)}}"> <b style="margin-left: 30px;">結束時間&nbsp;:</b> <input type="datetime-local" name="end_time" class="form-control" value="{{old('end_time',$data->end_time)}}"> <span class="help-block m-b-none"><i class="fa fa-info-circle"
>
</i>秒置為 00,因此不顯示秒數.</span> </div> </div>
$data = TeacherRestSchedule::find($id);
$data->start_time = timeToW3c($data->start_time);


function timeToW3c($datetime, $timezone = 'UTC')
{
    $timestamp = strtotime($datetime);
    if (!$timestamp) {
        return null;
    }
    $date
= Carbon::createFromTimeStamp($timestamp, 'UTC'); $date->setTimezone($timezone); $w3c = str_replace(' ', 'T', $date->format('Y-m-d H:i:00')); return $w3c; }

能夠識別的格式: 2018-12-02T12:30

效果圖

這裡寫圖片描述