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

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

内容简介: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


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

查看所有标签

猜你喜欢:

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

ActionScript 3.0 Cookbook

ActionScript 3.0 Cookbook

Joey Lott、Darron Schall、Keith Peters / Adobe Dev Library / 2006-10-11 / GBP 28.50

Well before Ajax and Microsoft's Windows Presentation Foundation hit the scene, Macromedia offered the first method for building web pages with the responsiveness and functionality of desktop programs......一起来看看 《ActionScript 3.0 Cookbook》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

html转js在线工具
html转js在线工具

html转js在线工具