4
votes

i have an input format like this, and i need to convert it to GMT format:

$input = array(
           "gmt" => "+7",
           "datetime" => "2017-10-10 12:10:12"
         );

the input data contain gmt array index which show the which gmt format, and the datetime index shows the date in "Y-m-d h:i:s" that needs to be convert from GMT+7 to GMT.

2
I Think you want to read about localization stackoverflow.com/questions/10971363/php-localizationStuiterSlurf

2 Answers

1
votes

Try this:

$input = array(
  "gmt" => "+7",
  "datetime" => "2017-10-10 12:10:12"
);

$ny = new DateTimeZone("GMT+7");
$gmt = new DateTimeZone("GMT");
$date = new DateTime( $input["datetime"], $ny );
$date->setTimezone( $gmt );

echo $date->format('Y-m-d H:i:s');
0
votes

Oneshot (not recommended):

echo date('Y-m-d h:i:s', strtotime($input['datetime'])+$input['gmt']*3600);