php convert datetime to UTC

后端 未结 16 1037
無奈伤痛
無奈伤痛 2020-11-27 12:30

I am in need of an easy way to convert a date time stamp to UTC (from whatever timezone the server is in) HOPEFULLY without using any libraries.

16条回答
  •  清酒与你
    2020-11-27 12:55

    Try the getTimezone and setTimezone, see the example

    (But this does use a Class)

    UPDATE:

    Without any classes you could try something like this:

    $the_date = strtotime("2010-01-19 00:00:00");
    echo(date_default_timezone_get() . "
    "); echo(date("Y-d-mTG:i:sz",$the_date) . "
    "); echo(date_default_timezone_set("UTC") . "
    "); echo(date("Y-d-mTG:i:sz", $the_date) . "
    ");

    NOTE: You might need to set the timezone back to the original as well

提交回复
热议问题