この文字列が2012-06-27 16:17:06
あり、GMT形式に変換したいと思います。
どうやってやるの?
どうもありがとう。
gmdate()を使用します。
を使用して現在の日付形式をUNIXタイムスタンプに変換してstrtotime
から、gmdate($format, $timestamp);
まあ、厳密に言えば、あなたはそれを行うことはできません。その日付が生成されたTZがわからない場合は、別のTZに変換できません。
その日付がDBからのものである場合は、おそらく元のTZで日付を照会できます。
$date = new DateTime( "2011-01-01 15:00:00", $original_TZ );
$date->setTimezone( "GMT" );
PHPのDateTimeオブジェクトは良い選択です:
$GMT = new DateTimeZone("GMT");
$date = new DateTime( "2011-01-01 15:00:00", $GMT );
$date->setTimezone( $newTZ );
echo $date->format('Y-m-d H:i:s');
// Set timeline
$time_line = time() +7200; // <-- this is timeline +2
$h = gmdate('h', $time_line);
$i = gmdate('i', $time_line);
$s = gmdate('s', $time_line);
$time = $h.":".$i.":".$s;
echo $time;
これを試してみてください、それはうまくいくでしょう
$newTZ = new DateTimeZone("Asia/Calcutta");
date_default_timezone_set("Asia/Calcutta");
$GMT = new DateTimeZone("GMT");
$date = new DateTime( "2018-09-20 6:00:00 PM", $newTZ );
$date->setTimezone($GMT);
echo $date->format('Y-m-d H:i:s');
これを試して。
$time = '2012-06-27 16:17:06';
echo date("l, F j, Y, g:i a",strtotime($time) ); // assuming gmt format
PHPでグリニッジ標準時を取得するにはどうすればよいですか?