简体   繁体   English

给定本地DateTime和lat / lon,如何确定NodeJ中的时区和偏移量?

[英]Given local DateTime and lat/lon, how to determine a timezone and offset in NodeJs?

In the past I implemented C# library which, given local DateTime and lat/lon , allowed to determine a timezone and offset . 过去,我实现了C#库,该库在给定本地DateTime和lat / lon的情况下允许确定时区和offset

I did the following: 我做了以下事情:

  • downloaded shapefiles from efele.net/maps/tz 从efele.net/maps/tz下载的shapefile
  • imported them into SQL Server 将它们导入到SQL Server
  • used them to get tzid from lat/lon 用它们来获取经纬度的tzid

Noda Time C# library was used to get all necessary information about timezone, offset, and DST. Noda Time C#库用于获取有关时区,偏移量和DST的所有必要信息。 It returns: 它返回:

  • Offset in minutes 偏移分钟
  • UTC DateTime UTC日期时间
  • Olson/IANA Timezone name Olson / IANA时区名称
  • Windows Timezone name Windows时区名称
  • bool IsDST 布尔IsDST

Now I need to reproduce this library in NodeJs + PostgreSQL. 现在,我需要在NodeJs + PostgreSQL中重现该库。 Is the suggested way of doing it: 是这样做的建议方法:

  • Import http://efele.net/maps/tz shapefiles to PostgreSQL http://efele.net/maps/tz shapefile导入PostgreSQL
  • Use Moment TimeZone library in NodeJs similar to how I used Noda Time in C# 在NodeJs中使用Moment TimeZone库,类似于我在C#中使用Noda Time的方法

Are there known pitfalls, difficulties? 有已知的陷阱,困难吗?

As you said, you need some actualized shapefile to map all timezones by geo coordinates . 如您所说,您需要一些实际的shapefile来通过geo坐标映射所有时区

You can use a module like geo-tz that natively support moment-timezone library. 您可以使用像geo-tz这样的模块,该模块本身支持moment-timezone库。 Or a more lightweight one like tz-lookup . 或更轻巧的像tz-lookup

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM