I'm really confused. How can I format a timestamp value to YYYY-MM-DDThh:mm:ssTZD
format?
\Carbon\Carbon::parse($created_at)->format('YYYY-MM-DDThh:mm:ssTZD')
I also tried
\Carbon\Carbon::parse($created_at)->format('Y-m-d\TH:i:sZ')
but it's not returning what I expect. YYYY-MM-DDThh:mm:ssTZD
is not a valid PHP date format, which is the representation of it in PHP?
CodePudding user response:
You can use toAtomString
or toIso8601String
$date->toAtomString();
$date->toIso8601String();
https://carbon.nesbot.com/docs/#api-commonformats
OR
$date->format('Y-m-d\TH:i:s.v\Z')
CodePudding user response:
You can use toIso8601ZuluString()
$dt->toIso8601ZuluString();// 2019-02-01T03:45:27Z
Further reading Common Formats