Home > Mobile >  PHP parsing date with timezone from a string
PHP parsing date with timezone from a string

Time:12-10

I want to parse the date with the timezone from a string in the format "2021-12-10T18:49:00-05:00". I tried to parse using "date('Y-m-d h:i:s', strtotime($myDate))". But it is returning date of next day. Any help is much appreciated.

CodePudding user response:

Use DateTimeInterface::ATOM to format your date:

date(DateTimeInterface::ATOM, strtotime('now'));

This outputs 2021-12-10T14:23:37 00:00

CodePudding user response:

short answer:

echo date('c'); //output 2021-12-10T17:28:24 03:00

to convert given date format use:

echo date('c', strtotime('2021-12-10')); //output 2021-12-10T00:00:00 03:00
  •  Tags:  
  • php
  • Related