admin管理员组

文章数量:1289957

how can I get user Time Zone in Wordpress if you don't know where the user comes from.

Let's say if a user is in USA I need to get USA Time Zone, if the user is in Germany I need to get Germany Time Zone.

how can I get user Time Zone in Wordpress if you don't know where the user comes from.

Let's say if a user is in USA I need to get USA Time Zone, if the user is in Germany I need to get Germany Time Zone.

Share Improve this question asked Jun 25, 2021 at 7:50 BesartBesart 1011 bronze badge 6
  • How do you know where a user is coming from? – kero Commented Jun 25, 2021 at 8:06
  • I don't know, I need to detect it programmatically, but I don't know how. – Besart Commented Jun 25, 2021 at 8:08
  • Ok, so that is where you need to start. Searching for "wordpress find country of visitor" already yields a couple of results. What have you tried of these and where are you currently failing? – kero Commented Jun 25, 2021 at 8:20
  • I tried this: link but it returns empty ip_info("Visitor", "Country"); – Besart Commented Jun 25, 2021 at 8:36
  • 3 As commented here, there is no reliable way of doing this. also getting a country wont give you the time zone per se, there is no "USA Time Zone" – vancoder Commented Jun 25, 2021 at 16:30
 |  Show 1 more comment

1 Answer 1

Reset to default 1

Since WordPress is a server-side framework/CMS, it likely doesn't have the functionality you're looking for. If you're looking for ways to obtain this information, the most reliable would likely be to ask the user.

To make it as painless as possible for the user, this functionality could be achieved via client-side scripting (ie. JavaScript) where you attempt to infer the user's timezone:

-new Date().getTimezoneOffset()/60;

And then ask the user to confirm that it is the correct timezone. Keep in mind, client side code is run on the user's machine and can be disabled entirely.

本文标签: phpHow to get User Time Zone in Wordpress