php日期更改为12小时格式并添加gmt +3 [关闭]

I am using date as:

 $date = date('m-d-Y H:i:s');

This inserts it as 24 hour and what I want is 12 hour format and add GMT +3, how can I do that?

If you want the GMT +3 timezone, you could apply this:

date_default_timezone_set('Etc/GMT+3');

Although I don't recommend it because PHP will not longer support that timezone. You might use one of the supported ones. And for the date being in 12-hour format use it this way:

$date = date('m-d-Y h:i:s');

Lowercase h format character is for

12-hour format of an hour with leading zeros

date_default_timezone_set("GMT"); for changing timezone..(replace gmt with +3 timezone name)

$date = date('m-d-Y h:i:s'); for 12 hour format..

And read the manual http://php.net/manual/en/function.date.php

You could just use

  $date = date("m-d-Y h:i:s", strtotime("now +3 GMT"));