阅读golang time文档
This commit is contained in:
@@ -55,6 +55,9 @@
|
|||||||
- [JSONFormatter](#jsonformatter)
|
- [JSONFormatter](#jsonformatter)
|
||||||
- [设置TimeStampFormat格式](#设置timestampformat格式)
|
- [设置TimeStampFormat格式](#设置timestampformat格式)
|
||||||
- [自定义Formatter](#自定义formatter)
|
- [自定义Formatter](#自定义formatter)
|
||||||
|
- [golang time](#golang-time)
|
||||||
|
- [get current time](#get-current-time)
|
||||||
|
- [monotonic clock](#monotonic-clock)
|
||||||
- [syntax](#syntax)
|
- [syntax](#syntax)
|
||||||
- [iota](#iota)
|
- [iota](#iota)
|
||||||
|
|
||||||
@@ -1143,6 +1146,25 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## golang time
|
||||||
|
### get current time
|
||||||
|
在golang中,可以通过`time`package获取当前时间,该包中提供了许多date和time相关的方法,可以通过`time.Time`类型来表示特定的时间点。
|
||||||
|
|
||||||
|
当前时间可以通过`time.Now`方法来进行获取,示例如下:
|
||||||
|
```go
|
||||||
|
fmt.Println(time.Now())
|
||||||
|
```
|
||||||
|
其返回结果如下所示:
|
||||||
|
```
|
||||||
|
2025-01-16 12:55:07.748015 +0800 CST m=+0.000000001
|
||||||
|
```
|
||||||
|
#### monotonic clock
|
||||||
|
上述返回结果中,`m=`部分代表monotonic clock,monotonic clock在拱廊内部使用,用于衡量时间差异。monotonic用于补偿`程序运行时对computer system clock的日期和时间造成的潜在修改`。
|
||||||
|
|
||||||
|
通过使用monotonic clock,如果在两次调用`time.Now`间隔5min的场景下,即使在调用的5分钟间隙内认为修改系统时间,两次调用`time.Now`返回值的差额仍然为5min。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## syntax
|
## syntax
|
||||||
### iota
|
### iota
|
||||||
`iota`关键字代表连续的整数变量,`0, 1, 2`,每当`const`关键字出现时,其重置为0
|
`iota`关键字代表连续的整数变量,`0, 1, 2`,每当`const`关键字出现时,其重置为0
|
||||||
|
|||||||
Reference in New Issue
Block a user