- This topic has 6 replies, 2 voices, and was last updated 3 years, 3 months ago by Elvin.
-
AuthorPosts
-
November 30, 2020 at 4:39 pm #1559459Dong
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!
November 30, 2020 at 8:33 pm #1559653ElvinStaffCustomer SupportHi,
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.
November 30, 2020 at 9:55 pm #1559727DongThat did it! You’re the man, Elvin! Thanks! It was driving me nuts! 🙂
November 30, 2020 at 10:00 pm #1559731DongBy 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.
November 30, 2020 at 10:22 pm #1559751ElvinStaffCustomer SupportBy 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-serverYou 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.
November 30, 2020 at 10:23 pm #1559753DongYeap, 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!
November 30, 2020 at 10:59 pm #1559781ElvinStaffCustomer SupportYeap, 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. 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.