tzdb: Simplified list of time zones and offsets, always up to date, full data included

栏目: IT技术 · 发布时间: 4年前

内容简介:This is a list and npm package of:The data and npm packages areThis is useful whenever you want to build a time zone select menu in your application.

tzdb

This is a list and npm package of:

  • "simplified" IANA time zones and their offset names
  • all existing IANA time zones names
  • and major cities (population > 5,000) with their associated time zones and offset names

The data and npm packages are automatically updated whenever there are changes to https://www.geonames.org/ which is generated from IANA databases.

This is useful whenever you want to build a time zone select menu in your application.

Available data

simplified-time-zones.json

This is most probably what you're looking for if you're trying to build a good current time zones selector in your application.

Example data:

{
  "timeZoneName":"America/Anchorage",
  "formatted":"-09:00 Alaska Time - Anchorage, Juneau",
  "group":[
    "America/Anchorage",
    "America/Juneau",
    "America/Metlakatla",
    "America/Nome",
    "America/Sitka",
    "America/Yakutat"
  ]
},
{
  "timeZoneName":"Pacific/Gambier",
  "formatted":"-09:00 Gambier Time - Gambier",
  "group":["Pacific/Gambier"]
},
{
  "timeZoneName":"America/Los_Angeles",
  "formatted":"-08:00 Pacific Time - Los Angeles",
  "group":[
    "America/Los_Angeles"
  ]
},

As you can see, we provide the time zone name and a pre-formatted version using more common offset names.

Notes:

  • Grouping: when two different time zones names are in the same country, same offset and dst rules then we merge them and select the time zone name from the biggest city
  • We provide two cities when grouping happens, ranked by population
  • We provide offset names ("Pacific Time") without dst and remove "Standard" and "Daylight"
  • This can be used to build a good enough (Google calendar like) select box of time zones, but it's your responsibility to handle dst and real offsets

cities-with-time-zones.json

This is a list of major cities (population > 5,000) and their associated time zone information, ranked by population. This is useful if you want to build an application where the user will type a city and you want the time zone information out of it.

Example data:

{
  "geonameId":"5368361",
  "name":"Los Angeles",
  "countryName":"United States",
  "timeZoneName":"America/Los_Angeles",
  "timeZoneOffsetNameWithoutDst":"Pacific Time",
  "population":3971883,
  "modificationDate":"2019-12-12"
},
{
  "geonameId":"1205733",
  "name":"Chittagong",
  "countryName":"Bangladesh",
  "timeZoneName":"Asia/Dhaka",
  "timeZoneOffsetNameWithoutDst":"Bangladesh Time",
  "population":3920222,
  "modificationDate":"2016-11-09"
},
{
  "geonameId":"1804651",
  "name":"Kunming",
  "countryName":"China",
  "timeZoneName":"Asia/Shanghai",
  "timeZoneOffsetNameWithoutDst":"China Time",
  "population":3855346,
  "modificationDate":"2014-08-14"
},
{
  "geonameId":"361058",
  "name":"Alexandria",
  "countryName":"Egypt",
  "timeZoneName":"Africa/Cairo",
  "timeZoneOffsetNameWithoutDst":"Eastern European Time",
  "population":3811516,
  "modificationDate":"2019-09-05"
},

time-zones-names.json

This is the raw list of all IANA time zones ranked by alphabetical order.

Example data:

"America/La_Paz",
"America/Lima",
"America/Los_Angeles",
"America/Lower_Princes",
"America/Maceio",
"America/Managua",
"America/Manaus",
"America/Marigot",
"America/Martinique",

NPM package

Installation:

npm add @vvo/tzdb

Usage:

import cities from "@vvo/tzdb/cities-with-time-zones.json";
import simplifiedTimeZones from "@vvo/tzdb/simplified-time-zones.json";
import timeZones from "@vvo/tzdb/time-zones-names.json";

Algolia

You can store cities information on a search engine like Algolia . There's a yarn build command you can use if you clone this repository to create your own Algolia index. The expected environment variables are:

ALGOLIA_APPLICATION_ID=... ALGOLIA_ADMIN_API_KEY=... ALGOLIA_INDEX_NAME=... yarn build

Here's a demo of the index:

tzdb: Simplified list of time zones and offsets, always up to date, full data included


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

深入浅出HTML5编程

深入浅出HTML5编程

弗里曼 (Eric Friiman)、罗布森 (Elisabdth Robson) / 东南大学出版社 / 2012-4 / 98.00元

《深入浅出HTML5编程(影印版)(英文)》就是你的特快车票,它可以带你学习如何使用今天的标准同时也会是明日的最佳实践来搭建Web应用。同时,你会了解HTML5的新API的基本知识,甚至你还会弄明白这些API是如何与你的网页进行交互,JaVaScript如何为它们提供动力,以及你如何使用它们来搭建能够打动你的老板并且吸引你的朋友的Web应用。一起来看看 《深入浅出HTML5编程》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器