create time with format character P in php -


i have utc time 15:00:00

timezone based utc offset +03:00

when tried create new time using utc time+utc offset , shows 12:00:00.

but need time 18:00:00

please give me suggestions.

$utc_offset="+03:00";    date("d m, y h:i a", strtotime("15:00:00 ".$utc_offset)) 

the code posted parses string '15:00:00 +03:00.

in plain english, string means "the local time 15:00 (3 pm) , located in timezone 3 hours @ east of gmt/utc". corresponding utc time 12:00.

it happens php has default timezone set utc (i guess default value in php.ini , didn't change it). why date() prints 07 sep, 2016 12:00 pm.

for me code prints 07 sep, 2016 03:00 pm because in timezone @ utc+3 , php.ini uses default.

don't use date() (or of date/time functions). of them don't know timezone, others work local time.

use datetime classes instead. can handle timezones , code shorter , more clear.

your concrete problem easy solve:

// parse input time in utc timezone $date = new datetime("15:00:00", new datetimezone("utc")); // change timezone local $date->settimezone(new datetimezone("+03:00")); // output local time echo($date->format("d m, y h:i a")); 

it displays:

07 sep, 2016 06:00 pm 

read more datetime, datetimezone, datetimeinterval , other datetime classes. modern way of handling date & time in php.


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -