如何找到与UTC相关的时区偏移量,以纬度和经度为单位

时间:2013-12-07 00:43:36

标签: lua timezone latitude-longitude utc timezone-offset

我在代码中使用weatherlib库来查找日出和日落时间,但我找不到用户当前时区的纬度和经度离线。以下是有关该主题的一些额外信息:

calc_sunrise的参考:

calc_sunrise (date, latitude, longitude, timezone)
Calculate the time of sunrise at the given date and location. Routines from the JavaScript code at http://www.esrl.noaa.gov/gmd/grad/solcalc/.
Parameters
- date: an os.date table representing the date for which to calculate the time of sunrise
- latitude: Latitude of the location
- longitude: Longitude of the location
- timezone: Timezone as an offset in hours from UTC at the given location
Return value:
- os.date table that holds the date and time when sunrise occurs

它们还具有calc_timezone_offset功能,但您需要当前时区的字符串。以下是它的参考:

calc_timezone_offset (timezone)
Calculate timezone offset from UTC in seconds for the given timezone. Uses external command date(1). Takes Daylight Saving Time into account if the local date command supports that. Tested only on Ubuntu Linux 10.04 and Solaris 10 operating systems. May not be very portable.
Parameters
- timezone: Timezone name, e.g. Europe/Helsinki, Asia/Bangkok, US/Pacific
Usage
- weatherlib.calc_timezone_offset('Europe/Helsinki') -- 7200
- weatherlib.calc_timezone_offset('Asia/Bangkok') -- 28800
- weatherlib.calc_timezone_offset('US/Pacific') -- -28800
Return value:
- Timezone offset in seconds from UTC. Positive for timezones ahead of UTC, negative for timezones behind UTC.

谢谢! 附:我确实寻找重复的问题,但没有人给我一个离线使用的答案。

编辑:指定我需要离线。

1 个答案:

答案 0 :(得分:0)

我错过了@MattJohnson的帖子中的离线部分。我从whereonearth-timezone获取了数据。谢谢!