Code Monkey home page Code Monkey logo

timezone's Introduction

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",
}

timezone's People

Watchers

toukii avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.