当前位置:网站首页>时区的区别及go语言的time库
时区的区别及go语言的time库
2022-07-05 23:45:00 【我是py呀】
UTC,GMT,CST是什么?
- 可以参考这篇文章:https://baijiahao.baidu.com/s?id=1732139602203523267
- UTC时间比中国上海表示的时区慢8个小时。
- CST: 2022-08-22 00:00:00 +0800 CST
- UTC: 2022-08-21 16:00:00 +0000 UTC
Go语言中time库常用的一些方法
time.Local (*time.Location): 获取当前系统的时区
time.UTC (*time.Location): UTC
func time.Parse(layout string, value string) (time.Time, error)
- 可以将字符串转化为go Time类型。 第一个 layout是对应的时间模板。 time库内置了很多的模板。 可以自定义 FormatTimeShort = “2006-01-02”, 模板只解析到年月日.
- 这个方法默认转换为的时间是 UTC时间。
func time.ParseInLocation(layout string, value string, loc *time.Location) (time.Time, error)
- 这个方法解析的时候可以传递时区信息。
func time.Now() time.Time
返回当前时区的时间。func (time.Time).UTC() time.Time
将具有时区的时间,转化为 UTC表示的时间。func (time.Time).Unix() int64
该方法将Time类型的时间转换为 时间戳,时间戳是不依赖时区的。默认是从 UTC时间规定的开始计算。func time.Unix(sec int64, nsec int64) time.Time
这个函数可以将时间戳转化为当前时区的Time类型时间。func (time.Time).MarshalJSON() ([]byte, error)
解析时间到json格式的函数。
注意:
- 使用时间的时候,要注意到时区的转换。
- 一般读取本地时区的时候,要注意本地时区的设置:
- 比如ubuntu系统,输入
date
指令,可以获取当前的时间。 timedatectl set-timezone Asia/Shanghai
设置当前的时区为 中国上海的时区。
- 比如ubuntu系统,输入
边栏推荐
- Use mapper: --- tkmapper
- QT a simple word document editor
- Problem solving win10 quickly open ipynb file
- 总结了 800多个 Kubectl 别名,再也不怕记不住命令了!
- Comparison of parameters between TVs tube and zener diode
- Research notes I software engineering and calculation volume II (Chapter 1-7)
- Redis high availability - master-slave replication, sentinel mode, cluster
- Russian Foreign Ministry: Japan and South Korea's participation in the NATO summit affects security and stability in Asia
- 424. The longest repeated character after replacement ●●
- TS type declaration
猜你喜欢
698. Divided into k equal subsets ●●
What if the C disk is not enough? Let's see how I can clean up 25g of temp disk space after I haven't redone the system for 4 years?
Rsync remote synchronization
el-cascader的使用以及报错解决
C reflection and type
Research notes I software engineering and calculation volume II (Chapter 1-7)
用列錶初始化你的vector&&initializer_list簡介
Rasa 3. X learning series -rasa 3.2.1 new release
STM32__06—单通道ADC
Breadth first search open turntable lock
随机推荐
【EF Core】EF Core与C# 数据类型映射关系
TS type declaration
Open3D 点云随机添加噪声
2022.6.20-6.26 AI industry weekly (issue 103): new little life
如何提升口才
用列錶初始化你的vector&&initializer_list簡介
Problem solving win10 quickly open ipynb file
多普勒效應(多普勒頻移)
CAS and synchronized knowledge
C # input how many cards are there in each of the four colors.
orgchart. JS organization chart, presenting structural data in an elegant way
14 MySQL-视图
Convert Chinese into pinyin
4 points tell you the advantages of the combination of real-time chat and chat robots
The PostgreSQL column reference 'ID' is ambiguous - PostgreSQL column reference'id'is ambiguous
PADS ROUTER 使用技巧小记
《牛客刷verilog》Part III Verilog企业真题
Brushless drive design -- on MOS drive circuit
20.移植Freetype字体库
Objective C message dispatch mechanism