当前位置:网站首页>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
}
}
边栏推荐
- HDU - 1260 Tickets(线性DP)
- KeePass realizes automatic input of web pages
- SAP HR 社会工作经历 0023
- Summary of common methods of object class (September 14, 2020)
- JNI uses asan to check memory leaks
- Display the server hard disk image to the browser through Servlet
- Live server usage
- 解析token的网址
- Flash encryption process and implementation of esp32
- May day C - most
猜你喜欢

Right click the idea file to create new. There is no solution to create new servlet

激光slam学习(2D/3D、偏实践)

Take you hand in hand to build Eureka client with idea

关于CH32库函数与STM32库函数的区别

Ora-01741 and ora-01704

Flash encryption process and implementation of esp32

Wechat applet development beginner 1

Chisel tutorial - 02 Chisel environment configuration and implementation and testing of the first chisel module

SAP HR reward and punishment information export

Pycharm basic settings latest version 2022
随机推荐
JNI uses asan to check memory leaks
保证接口数据安全的10种方案
Benchmarking Detection Transfer Learning with Vision Transformers(2021-11)
Flash download setup
P2141 [noip2014 popularization group] abacus mental arithmetic test
Boost regex library source code compilation
Oracle string sorting
Enumeration, simulation, and sorting
【leetcode】day1
Stringutils tool class
BSS 7230 flame retardant performance test of aviation interior materials
Navicat connects Oracle
Alibaba cloud MySQL cannot connect
redis缓存工具类,值得拥有~
一份假Offer如何盗走了「Axie infinity」5.4亿美元?
SQL database execution problems
AITM3.0005 烟雾毒性测试
May day C - most
[STM32 + esp-12s connect Tencent cloud IOT development platform 1] creation of cloud platform and burning of at firmware
[experiment sharing] log in to Cisco devices through the console port