php convert datetime to UTC

后端 未结 16 1059
無奈伤痛
無奈伤痛 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

    I sometime use this method:

    // It is not importnat what timezone your system is set to.
    // Get the UTC offset in seconds:
    $offset = date("Z");
    
    // Then subtract if from your original timestamp:
    $utc_time = date("Y-m-d H:i:s", strtotime($original_time." -".$offset." Seconds"));
    

    Works all MOST of the time.

提交回复
热议问题