• Resolved WPChina

    (@wordpresschina)


    On the top of my website I have the current date and I use a simple php stroing as follows:

    <?php echo strftime("%B %d, %Y");?>

    The problem is that my server is located in GMT -7 and I live in GMT +8. There must be an easy way to solve this in PHP, but I can’t find much on google that makes sense.

    Anybody know how to do this?

    Tks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    If you’re using PHP 5 or up, then it’s easy. Just add:
    date_default_timezone_set("Timezone/String");

    To the beginning of your code. This sets the timezone that you want to operate in. Valid timezone strings can be found here: https://php.net/manual/en/timezones.php

    That is the best way to do it because it accounts for all timezone changes and DST and everything automatically. Easy. Simple.

    If you *don’t* have PHP 5, then my advice is to upgrade. But if that’s too difficult, this sort of thing will work:
    gmstrftime("%whatever",time()+$offset);

    Change $offset to be whatever your offset is from GMT in seconds. Note that this will not account for DST changes and such.

    Thread Starter WPChina

    (@wordpresschina)

    Ahh, thank you Otto42! I am on a lower level of PHP and the second suggestion worked perfectly!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How can I offset php time in strftime?’ is closed to new replies.