我有一个带有用户日期的json。日期可以采用以下格式:
<table id="datatable2" class="table order-column hover">
<thead>
<tr>
<th>Truck NO.</th>
<th>Date</th>
<th>Product</th>
<th>Volume</th>
<th>Volume @20</th>
<th>Depot</th>
<th>Driver</th>
<th>Driver Tel</th>
<th>Driver ID</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{% for car in loaded %}
<tr class="gradeX">
<td>{{car.order.truck.truck_number}}</td>
<td>{{car.order.date}}</td>
<td>{{car.order.product}}</td>
<td>{{car.order.volume}}</td>
<td>{{car.order.volume_delivered}}</td>
<td>{{car.order.depot}}</td>
<td>{{car.order.truck.driver_name}}</td>
<td>{{car.order.truck.driver_phone_number}}</td>
<td>{{car.order.truck.driver_id_number}}</td>
<td><input type="checkbox" id="toggle-two"></td>
</tr>
{% endfor %}
</tbody>
</table>
如何在全球范围内解析这些日期?
当我使用时:
"bdate": "25.10",
"bdate": "8.7.1990"
"bdate": "13.10.1984"
"bdate": "7.3"
我收到错误消息:
Carbon::parse($people->bdate)
答案 0 :(得分:1)
可能有一个更简单的解决方案,对此进行了测试并且有效
$date = [null, null, null];
$data = explode('.', "25.10");
foreach ($data as $key => $da) {
$date[$key] = $da;
}
$date = Carbon::createFromDate($date[2], $date[1], $date[0]);
答案 1 :(得分:1)
这可能是解决您问题的另一种方法。
function getBirthDateInCarbon($date){
$count = substr_count($date,'.');
if($count==1){
return \Carbon\Carbon::createFromFormat('d.m', $date);//default year will be current year
}
return \Carbon\Carbon::createFromFormat('d.m.Y', $date);
}