I want to format my date to be like this yyyyMMddHHmmss
Here is my currentcode
$now = Carbon::now()->toString();
$format='yyyyMMddHHmmss';
//$parsed = Carbon::parse($now);
$formatted = Carbon::parse($now);
//$x = strtotime($now);
dd($formatted);
I got a date like this
Carbon\Carbon @1580189543 {#223 ▼
date: 2020-01-28 13:32:23.0 +08:00
}
If I modify my code like this
$formatted = Carbon::parse($now,$format);
dd($formatted);
It says Unknown or bad timezone (yyyyMMddHHmmss)
I just want my date to become like this 20200128 133223
Does anyone know how to do it?
像这样在 Carbon 上使用格式:
Carbon::now()->format('YmdHis')
Your desire format is like
Carbon::now()->format('yymd his')
For details https://www.php.net/manual/en/class.datetime.php
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.