当前位置:网站首页>Go time package common functions
Go time package common functions
2022-07-07 23:44:00 【Cough, Hello, please give me more advice!】
now := time.Now() // Get the current time
fmt.Printf(" current time %v\n", now)
year := now.Year() // year
month := now.Month() // month
day := now.Day() // Japan
hour := now.Hour() // Hours
minute := now.Minute() // minute
second := now.Second() // second
secondsEastOfUTC := int((8 * time.Hour).Seconds())
beijing := time.FixedZone("Beijing Time", secondsEastOfUTC)
// fmt.Print(beijing.String())
// Beijing time. 2022-02-22 22:22:22.000000022 +0800 CST
t := time.Date(2022, 02, 22, 22, 22, 22, 22, beijing)
var (
sec = t.Unix()
msec = t.UnixMilli()
usec = t.UnixMicro()
)
// Turn the second timestamp into a time object ( The second parameter is insufficient 1 Nanoseconds per second )
timeObj := time.Unix(sec, 22)
fmt.Println(timeObj) // 2022-02-22 22:22:22.000000022 +0800 CST
timeObj = time.UnixMilli(msec) // Millisecond timestamps are converted to time objects
fmt.Println(timeObj) // 2022-02-22 22:22:22 +0800 CST
timeObj = time.UnixMicro(usec) // Microsecond timestamps are converted to time objects
fmt.Println(timeObj) // 2022-02-22 22:22:22 +0800 CST
time.Duration yes time A type of package definition , It represents the time between two time points , In nanoseconds .time.Duration A time interval , The longest period that can be expressed is about 290 year .
time The constants of the interval type defined in the package are as follows :
const (
Nanosecond Duration = 1
Microsecond = 1000 * Nanosecond
Millisecond = 1000 * Microsecond
Second = 1000 * Millisecond
Minute = 60 * Second
Hour = 60 * Minute
)
for example :time.Duration Express 1 nanosecond ,time.Second Express 1 second
now := time.Now()
later := now.Add(time.Hour) // Current time plus 1 Hours later
fmt.Println(later)
func tickDemo() {
ticker := time.Tick(time.Second) // Define a 1 Second interval timer
for i := range ticker {
fmt.Println(i)// Tasks that are performed every second
}
}
边栏推荐
- Ora-01741 and ora-01704
- Boost regex library source code compilation
- Design and implementation of spark offline development framework
- Pycharm essential plug-in, change the background (self use, continuous update) | CSDN creation punch in
- One of the anti climbing methods
- 【实验分享】通过Console口登录到Cisco设备
- ASP. Net open web page
- 二叉排序树【BST】——创建、查找、删除、输出
- ASP. Net core middleware request processing pipeline
- MongoDB快速入门
猜你喜欢
随机推荐
AITM3.0005 烟雾毒性测试
蓝桥ROS中使用fishros一键安装
0-1 knapsack problem
C - minute number V3
2022.7.7-----leetcode.648
[untitled]
Design and implementation of spark offline development framework
Interface
Oracle string sorting
Benchmarking Detection Transfer Learning with Vision Transformers(2021-11)
JNI uses asan to check memory leaks
【leetcode】day1
Svn relocation
MP4文件格式解析之结合实例分析
One of the anti climbing methods
HDU - 1260 Tickets(线性DP)
【7.4】25. K 个一组翻转链表
SAP memory parameter tuning process
Resolve the URL of token
【7.5】15. Sum of three numbers


![P1067 [noip2009 popularity group] polynomial output (difficult, pit)](/img/1f/a798879a0d65eccefa339b288f2102.jpg)






