Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert datetime to include utc timezone php

I am trying to convert datetime to a UTC timecode using PHP, how do I convert 2022-05-14 13:30:30 so it will come out as 2022-05-14T13:30:30+01:00

Thanks

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The format can be obtained with the method toAtomString(). With my timezone settings, i got the timezone 02:00, so i had to use setTimezone() and specifying the timezone on the parsing. Can be left out, if yours is correct.

Carbon::parse('2022-05-14 13:30:30', 'Europe/london')
    ->setTimezone('Europe/london')
    ->toAtomString();

This will format the date as follows 2022-05-14T13:30:30+01:00.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading