当前位置:网站首页>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
}
}
边栏推荐
- 【实验分享】通过Console口登录到Cisco设备
- Chisel tutorial - 04 Control flow in chisel
- Live server usage
- [untitled]
- 95.(cesium篇)cesium动态单体化-3D建筑物(楼栋)
- @Configuration注解的详细介绍
- Reverse output three digit and arithmetic sequence
- Progress broadcast | all 29 shield machines of Guangzhou Metro Line 7 have been launched
- Apng2gif solutions to various problems
- Come on, brother
猜你喜欢
Interface
Chisel tutorial - 03 Combinatorial logic in chisel (chisel3 cheat sheet is attached at the end)
Map operation execution process
Design and implementation of spark offline development framework
C method question 1
Chisel tutorial - 02 Chisel environment configuration and implementation and testing of the first chisel module
Balanced binary tree [AVL tree] - insert, delete
神奇快速幂
Anxinco EC series modules are connected to the multi protocol access products of onenet Internet of things open platform
[STM32 + esp-12s connect Tencent cloud IOT development platform 1] creation of cloud platform and burning of at firmware
随机推荐
Pycharm basic settings latest version 2022
[stm32+esp8266 connect Tencent cloud IOT development platform 2] stm32+esp8266-01s connect Tencent cloud
2022 certified surveyors are still at a loss when preparing for the exam? Teach you how to take the exam hand in hand?
Chisel tutorial - 05 Sequential logic in chisel (including explicit multi clock, explicit synchronous reset and explicit asynchronous reset)
二叉排序树【BST】——创建、查找、删除、输出
webflux - webclient Connect reset by peer Error
Boost regex library source code compilation
Dependency injection
Design and implementation of spark offline development framework
Wechat applet development beginner 1
Interface
Anti climbing means cracking the second
平衡二叉树【AVL树】——插入、删除
受限线性表
c—线性表
gorm 关联关系小结
0-1 knapsack problem
SAP HR reward and punishment information export
Ora-02437 failed to verify the primary key violation
SAP HR 劳动合同信息 0016