Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mbmohib's avatar

How to parse youtube publishedAt date with carbon ?

I'm working with Youtube API, the return date is "2017-03-25T10:59:15.000Z" in this format, I want to format it something like this 25-March-2017 without time! How can I do it with Carbon ? Or any other way ? Thanks !

0 likes
2 replies
Cronix's avatar
Cronix
Best Answer
Level 67

You'd need to do more than just change the format of the date. The date is written in UTC time (as denoted by the Z at the end), so you'd also probably want to convert it to your local timezone or it will be off by potentially quite a few hours.

$newDate = Carbon::parse($yourDateString)->format('j-F-Y'); will give you the format you want. http://php.net/manual/en/function.date.php

Add $newDate->setTimezone('America/Los_Angeles'); with your local timezone to convert it to your local time.

More on Carbon here: http://carbon.nesbot.com/docs/

mbmohib's avatar

It worked :D also didn't know about the timezone! Thank you so much!

Please or to participate in this conversation.