node.js - 从 NodeJS 中的国家和州获取时区
问题描述
因此,从国家这样的输入:美国和州:CA我需要获取时区。
我在这里看到了这个回复:Get timezone directly from Country and State Google API,但问题是 Google API 需要经度和纬度,所以我想知道我是否首先需要查找这些值。有没有直接获取时区的选项?
谢谢
解决方案
Moment.js gives you some functionality to do this
I have installed it with npm install moment-timezone
Then you can get the TimeZone as follows here for California using Los_Angeles
var moment = require('moment-timezone');
moment().tz("America/Los_Angeles").format();
var a = moment.tz("2013-11-18 11:55", "America/Los_Angeles");
var b = moment.tz("2013-11-18 11:55", "America/Toronto");
console.log(a.format()); // 2013-11-18T11:55:00-08:00
console.log(b.format()); // 2013-11-18T11:55:00-05:00
console.log(a.utc().format()); // 2013-11-18T19:55:00Z
console.log(b.utc().format()); // 2013-11-18T16:55:00Z
推荐阅读
- django - Django:如何在 order_by 中处理特殊字符
- matrix - 如何计算 ARKit 的 ARCamera 给出的投影矩阵?
- swift - UIViewControllerRepresentable 之间的交互可能吗?
- typescript - 如何对过滤 Object.entries 进行类型保护?
- http - elasticsearch url/uri 的单位
- python - + 不支持的操作数类型:“int”和“str”(python)
- python - 文本文件从 txt 文件中读取输入变量
- unity3d - 粒子系统未播放
- django - Django-tables2 将 html 属性添加到列
- python - 在不考虑周末的情况下,如何确保日期显示为雅虎财经/谷歌财经?