Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/toukii/timezone

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/toukii/timezone

  • v0.0.0-20200306141624-81ea595ca077
  • Source
  • Go
  • Socket score

Version published
Created
Source

timezone

转换依据:

时区时间转换为时间time.Time

time.Parse("2006-01-02T15:04:05Z07:00", "2018-10-01T16:27:00+08:00")

将时间化为这种字符格式,Parse后就可以得到time.Time

那么,需要维护一份时区的对应格式:

timezones = map[int32]string{
	24: "+00:00",
	1:  "+01:00",
	2:  "+02:00",
	3:  "+03:00",
	4:  "+04:00",
	5:  "+05:00",
	6:  "+06:00",
	7:  "+07:00",
	8:  "+08:00",
	9:  "+09:00",
	10: "+10:00",
	11: "+11:00",
	12: "+12:00",
	13: "-01:00",
	14: "-02:00",
	15: "-03:00",
	16: "-04:00",
	17: "-05:00",
	18: "-06:00",
	19: "-07:00",
	20: "-08:00",
	21: "-09:00",
	22: "-10:00",
	23: "-11:00",
}

时区对应:

Zonenames = map[int32]string{
	24: "中时区",
	1:  "东一区",
	2:  "东二区",
	3:  "东三区",
	4:  "东四区",
	5:  "东五区",
	6:  "东六区",
	7:  "东七区",
	8:  "东八区",
	9:  "东九区",
	10: "东十区",
	11: "东十一区",
	12: "东西十二区",
	13: "西一区",
	14: "西二区",
	15: "西三区",
	16: "西四区",
	17: "西五区",
	18: "西六区",
	19: "西七区",
	20: "西八区",
	21: "西九区",
	22: "西十区",
	23: "西十一区",
}

时间戳转换为时区时间

首先,时间戳转换为时间后:time.Unix(unix, 0), 要有所在时区的地址才可以转换为该时区的时间。

获得时间区域:

loc, err := time.LoadLocation(zone)

常见的时区有其代表的城市,如:

0: "Europe/London",
8: "Asia/Shanghai",
9: "Asia/Tokyo",

还有一种表示 Etc:

zones = map[int32]string{
	24: "Etc/GMT+0",
	1:  "Etc/GMT-1",
	2:  "Etc/GMT-2",
	3:  "Etc/GMT-3",
	4:  "Etc/GMT-4",
	5:  "Etc/GMT-5",
	6:  "Etc/GMT-6",
	7:  "Etc/GMT-7",
	8:  "Etc/GMT-8",
	9:  "Etc/GMT-9",
	10: "Etc/GMT-10",
	11: "Etc/GMT-11",
	12: "Etc/GMT-12",
	13: "Etc/GMT+1",
	14: "Etc/GMT+2",
	15: "Etc/GMT+3",
	16: "Etc/GMT+4",
	17: "Etc/GMT+5",
	18: "Etc/GMT+6",
	19: "Etc/GMT+7",
	20: "Etc/GMT+8",
	21: "Etc/GMT+9",
	22: "Etc/GMT+10",
	23: "Etc/GMT+11",
}

FAQs

Package last updated on 06 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc