当前位置:网站首页>时区的区别及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系统,输入
边栏推荐
- Russian Foreign Ministry: Japan and South Korea's participation in the NATO summit affects security and stability in Asia
- How to enable relationship view in phpMyAdmin - how to enable relationship view in phpMyAdmin
- Neural structured learning - Part 3: training with synthesized graphs
- Which side projects can be achieved? Is it difficult for we media to earn more than 10000 a month?
- Bao Yan notebook IV software engineering and calculation volume II (Chapter 8-12)
- 转:未来,这样的组织才能扛住风险
- Initialiser votre vecteur & initialisateur avec une liste Introduction à la Liste
- 帶外和帶內的區別
- 20220703 week race: number of people who know the secret - dynamic rules (problem solution)
- Hcip course notes-16 VLAN, three-tier architecture, MPLS virtual private line configuration
猜你喜欢
用列錶初始化你的vector&&initializer_list簡介
Part III Verilog enterprise real topic of "Niuke brush Verilog"
C# 反射与Type
Senparc.Weixin.Sample.MP源码剖析
Spire Office 7.5.4 for NET
Huawei simulator ENSP - hcip - MPLS experiment
Spécifications techniques et lignes directrices pour la sélection des tubes TVS et ESD - Recommandation de jialichuang
开源crm客户关系统管理系统源码,免费分享
Initialiser votre vecteur & initialisateur avec une liste Introduction à la Liste
How to rotate the synchronized / refreshed icon (EL icon refresh)
随机推荐
Spire Office 7.5.4 for NET
【GYM 102832H】【模板】Combination Lock(二分图博弈)
SpreadJS 15.1 CN 与 SpreadJS 15.1 EN
[classical control theory] summary of automatic control experiment
VBA fast switching sheet
QT--线程
Spreadjs 15.1 CN and spreadjs 15.1 en
Spire.PDF for NET 8.7.2
[Yu Yue education] NC machining technology reference materials of Shaanxi University of science and technology
Huawei simulator ENSP - hcip - MPLS experiment
Difference between out of band and in band
【EF Core】EF Core与C# 数据类型映射关系
shardingsphere源码解析
orgchart. JS organization chart, presenting structural data in an elegant way
【luogu P3295】萌萌哒(并查集)(倍增)
Add noise randomly to open3d point cloud
多普勒效应(多普勒频移)
做自媒体影视短视频剪辑号,在哪儿下载素材?
Convert Chinese into pinyin
俄外交部:日韩参加北约峰会影响亚洲安全稳定