How to find GMT date/time by country name?

后端 未结 4 1976
既然无缘
既然无缘 2020-12-14 04:03

How can I find country name -> GMT date/time to that I can do like following:

Example:

$datetime = new GMT_search(\'America\');  //output: 2010-01-01         


        
4条回答
  •  萌比男神i
    2020-12-14 04:30

    You can't do it quite like that, since a lot of countries have multiple timezones. You could store the timezone by the name of a city instead, but I'd use an integer with the timezone offset in seconds.

    You can get a list of timezones by continent/city from this function: [www.php.net/manual/en/function.timezone-identifiers-list.php][1]

    You can get the respective offset from this function: [www.php.net/manual/en/datetimezone.getoffset.php][2]

    When you have a valid offset, you can use gmdate() instead of date() to get a date in your format without the timezone/dst adjustment. Just pass the time() + the ajustment you have stored: [www.php.net/manual/en/function.gmdate.php][3]

提交回复
热议问题