Archived topic
Wrong time shown
6 replies · Started by Dong on November 30, 2020
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!
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.
That did it! You're the man, Elvin! Thanks! It was driving me nuts! :)
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.
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.
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!
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. :)