[Resolved] Wrong time shown

Home Forums Support [Resolved] Wrong time shown

Home Forums Support Wrong time shown

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1559459
    Dong

    Hi guys,

    I’ve had this issue for a while and can’t figure it out. I use

    <?php echo date( ‘l, F jS, Y’ ); ?>

    to show the current date on the front page (https://dongknows.com — the line only available on desktop), under the main NAV. For some reason, it always uses GMT (London) time, no matter what time zone I set using Wordpess settings (currently at Los Angeles). As a result, the date is always many hours ahead. It’s showing December 1st right now, even though it’s only 4:40 PM November 30 in LA.

    The crazy part is when I use

    <?php echo get_option(‘timezone_string’); ?>

    right next to the line above, it’d show the correct time zone.

    Can you please point me to the right direction as to how to fix it?

    Thanks!

    #1559653
    Elvin
    Staff
    Customer Support

    Hi,

    You can use echo current_time('l, F jS, Y',0);.

    0 means it will use the local timezone set on the site. 1 means it will use GMT (London) time.

    A wise man once said:
    "Have you cleared your cache?"

    #1559727
    Dong

    That did it! You’re the man, Elvin! Thanks! It was driving me nuts! 🙂

    #1559731
    Dong

    By the way, do you know what I can do to show that of the local time (viewer’s time, that is). So if somebody in London right now is viewing the site, they’ll see December 1, 2020, while it’s still November 30, 2020, in LA?

    Thanks again.

    #1559751
    Elvin
    Staff
    Customer Support

    By the way, do you know what I can do to show that of the local time (viewer’s time, that is). So if somebody in London right now is viewing the site, they’ll see December 1, 2020, while it’s still November 30, 2020, in LA?

    This is pretty tricky to do and to be frank, its a site customization that is outside of our scope.

    But to help you out, check these:
    https://stackoverflow.com/questions/2705067/how-can-i-get-the-users-local-time-instead-of-the-servers-time
    https://stackoverflow.com/questions/863474/automatically-detect-users-current-local-time-with-javascript-or-php
    https://stackoverflow.com/questions/13/how-to-determine-a-users-timezone-in-a-web-server

    You can go for the simple answer which is JavaScript or implement some sort of a GeoIP lookup that gets the offset between the visitor IP’s timezone & the site’s server time.

    A wise man once said:
    "Have you cleared your cache?"

    #1559753
    Dong

    Yeap, I thought so, too. I tried a few things already and failed. Guess it’s not worth it. Thanks for trying, Elvin. Happy holidays! Stay safe!

    #1559781
    Elvin
    Staff
    Customer Support

    Yeap, I thought so, too. I tried a few things already and failed. Guess it’s not worth it. Thanks for trying, Elvin. Happy holidays! Stay safe!

    Happy holidays to you too. No problem. 🙂

    A wise man once said:
    "Have you cleared your cache?"

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.