[英]How to get the current date and time in YYYY-MM-DD HH: MM? LARAVEL 4
[英]Laravel how to get current Time and Date value
我正在開發一個考勤管理系統。因此,我的主管要求我開發以下視圖以獲取考勤時間和日期值。
所有記錄都需要根據受訓者ID保存在數據庫中。根據該視圖,如果具有以上ID的復選框選中該復選框,然后按標記按鈕,則必須將時間值和受訓者ID准時保存在數據庫中。
然后,如果將其標記一次,則Date值也需要保存在數據庫中。
誰能為我建議相關的控制器功能?
這是相關的上述觀點
<table class="table table-striped">
<thead>
<th>Trainee ID</th>
<th>Name with Initials</th>
<th>Time</th>
<th>Mark Here!</th>
</thead>
<tbody>
@foreach($items as $item)
<tr>
<td>{{ $item->trainee_id }}</td>
<td>{{ $item->name_with_initials }}</td>
<td>
<label><input type="checkbox" value=""> Time</label>
</td>
<td>
<a class="btn btn-info" href="Bankdetails/{{ $item->trainee_id }}">Mark Here</a>
</td>
</tr>
@endforeach
</tbody>
</table>
嘗試這個
public function store(Request $request)
{
$request['time']=date("Y-m-d h:i:s a", time());
attendance::create($request->all());
return view('traineeattendance.attendanceo');
}
您可能要在這里使用Carbon
函數
參考一些文檔: https : //github.com/briannesbitt/Carbon
Laravel附帶有Carbon依賴項。
Carbon::now()
,如果需要,包括Carbon\\Carbon
命名空間。
編輯(用法和文檔)
假設我想檢索日期和時間並將其輸出為字符串。
$mytime = Carbon\Carbon::now();
echo $mytime->toDateTimeString();
這將以Ymd H:i:s
的通常格式Ymd H:i:s
,其中有許多預先創建的格式,並且您不太可能需要用Carbon再次弄亂PHP日期時間字符串。
文檔: https://github.com/briannesbitt/Carbon
: https://github.com/briannesbitt/Carbon
Carbon的字符串格式: http://carbon.nesbot.com/docs/#api-formatting
: http://carbon.nesbot.com/docs/#api-formatting
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.