Return local time from unix timestamp with timezone identifier in php

前端 未结 1 1823
心在旅途
心在旅途 2020-12-12 00:20

I have a dropdown box on a webpage that takes a timezone identifier as the value (however I can change it to save the GMT offset if that is a better choice). Currently a use

相关标签:
1条回答
  • 2020-12-12 00:48

    The easiest approach would be to use DateTime with:

    $t = new DateTime();
    $t->setTimestamp( $time=time() );
    $t->setTimeZone(new DateTimeZone("America/Denver"));
    print $t->format(DateTime::RFC850);
    

    The timezone can be changed at will to cause the format function to recalculate the local time.

    0 讨论(0)
提交回复
热议问题