当前位置:网站首页>时区的区别及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系统,输入
边栏推荐
- 20.移植Freetype字体库
- 【LeetCode】5. Valid palindrome
- Go language introduction detailed tutorial (I): go language in the era
- Laser slam learning record
- XML configuration file (DTD detailed explanation)
- 用列錶初始化你的vector&&initializer_list簡介
- How to enable relationship view in phpMyAdmin - how to enable relationship view in phpMyAdmin
- 跟着CTF-wiki学pwn——ret2libc1
- GFS分布式文件系統
- Open3D 点云随机添加噪声
猜你喜欢
随机推荐
[classical control theory] summary of automatic control experiment
C file and folder operation
"14th five year plan": emphasis on the promotion of electronic contracts, electronic signatures and other applications
Rasa 3. X learning series -rasa 3.2.1 new release
mysql-全局锁和表锁
Rsync remote synchronization
15 MySQL-存储过程与函数
【luogu P3295】萌萌哒(并查集)(倍增)
4点告诉你实时聊天与聊天机器人组合的优势
C reflection and type
Qt 一个简单的word文档编辑器
14 MySQL view
GFS distributed file system
【二叉搜索树】增删改查功能代码实现
When to use useImperativeHandle, useLayoutEffect, and useDebugValue
MySQL replace primary key delete primary key add primary key
2022.6.20-6.26 AI industry weekly (issue 103): new little life
GFS Distributed File System
TVS管和ESD管的技術指標和選型指南-嘉立創推薦
多普勒效应(多普勒频移)









