Laravel-在编辑表单中显示DateTime值

时间:2018-12-04 02:13:17

标签: jquery html laravel laravel-5 eloquent

如何在我的编辑表单中显示作为DateTime值的数据?

input="datetime-local."

以下是我的DateTime值:2018-04-02 04:04:00.

我希望它显示在此输入中:

<input type="datetime-local" name="flight_date" class="form-control">

我的 $ variable->数据

$aircraftFlight->flight_date

编辑 VAR DUMP

  

object(App \ AircraftFlights)#527(26){[“表格”:受保护的] =>   字符串(16)“ aircraft_flights” [“ primaryKey”] =>字符串(2)“ id”   [“ timestamps”] => bool(false)[“ connection”:protected] => string(5)   “ mysql” [“ keyType”:受保护] =>字符串(3)“ int” [“递增”] =>   bool(true)[“ with”:protected] => array(0){} [“ withCount”:protected] =>   array(0){} [“ perPage”:protected] => int(15)[“ exists”] => bool(true)   [“ wasRecentlyCreated”] => bool(false)[“ attributes”:protected] =>   array(9){[“ id”] => int(1)[“ flight_number”] =>字符串(10)“ AA-0000003”   [“ iata_flight_number”] =>字符串(5)“ ABCD2” [“ flight_date”] =>   string(19)“ 2018-04-02 04:04:00” [“ departure_time”] =>字符串(19)   “ 2018-05-04 01:59:00” [“ arrival_time”] =>字符串(19)“ 2018-05-05   13:59:00“ [” from_location“] =>字符串(11)”阿富汗“   [“目的地”] =>字符串(7)“阿尔巴尼亚” [“ aircraft_id”] => int(1)}   [“原始”:受保护] => array(9){[“” id“] => int(1)   [“ flight_number”] =>字符串(10)“ AA-0000003” [“ iata_flight_number”] =>   string(5)“ ABCD2” [“ flight_date”] => string(19)“ 2018-04-02 04:04:00”   [“ departure_time”] =>字符串(19)“ 2018-05-04 01:59:00”   [“ arrival_time”] =>字符串(19)“ 2018-05-05 13:59:00”   [“ from_location”] =>字符串(11)“阿富汗” [“目的地”] =>   string(7)“ Albania” [“ aircraft_id”] => int(1)} [“ changes”:受保护] =>   array(0){} [“ casts”:受保护] => array(0){} [“ dates”:protected] =>   array(0){} [“ dateFormat”:受保护的] => NULL [“ appends”:受保护的] =>   array(0){} [“ dispatchesEvents”:protected] => array(0){}   [“ observables”:受保护的] => array(0){} [“ relations”:受保护的] =>   array(0){} [“ touches”:受保护] => array(0){}   [“隐藏”:受保护] => array(0){} [“可见”:受保护] => array(0){   } [“ fillable”:受保护] => array(0){} [“ guarded”:受保护] =>   array(1){[0] =>字符串(1)“ *”}}

3 个答案:

答案 0 :(得分:0)

将变量放在输入类型的文本值上

<input type="text" name="flight_date" class="form-control" value="{{ $aircraftFlight->flight_date }}">

您可以使用php date()函数设置变量的格式,这里是链接:http://php.net/manual/en/function.date.php

格式化为此

date('Y-m-d h:i:s', strtotime($aircraftFlight->flight_date))

答案 1 :(得分:0)

尝试使用碳素来设置日期格式:

<input type="datetime-local" name="flight_date" class="form-control" value="{{ \Carbon\Carbon::parse($aircraftFlight->flight_date)->format('yyyy-MM-ddThh:mm')}}">

  

注意:Firefox,Safari或Internet Explorer 12(或更早版本)不支持type =“ datetime-local”。

答案 2 :(得分:0)

我将使用日期时间选择器,其输入类型为文本,并将ID设置为flight_date

看看这个:

https://eonasdan.github.io/bootstrap-datetimepicker/

这是我遇到的第一个

希望这会有所帮助

更新

这是我们在工作中使用的,我知道它是有效的

https://www.eyecon.ro/bootstrap-datepicker/

尝试一下。

相关问题