当前位置:网站首页>Go language time Format pit

Go language time Format pit

2022-06-09 12:24:00 . fried eggs with tomatoes

Problem description

Format The time of future output is the same as now It's different

package main

import (
	"fmt"
	"time"
)

func main() {
    
	now := time.Now()
	fmt.Println(now)
	format := now.Format("2006-01-01 15:04:05")
	fmt.Println(format)
}

 Insert picture description here

terms of settlement

package main

import (
	"fmt"
	"time"
)

func main() {
    
	now := time.Now()
	fmt.Println(now)
	format := now.Format("2006-01-02 15:04:05")
	fmt.Println(format)
}

 Insert picture description here
Use time.Format Format time parameter layout It has to be transmitted "2006-01-02 15:04:05", Why? ? No why? , This is the worst place , It is said that this date is GO The birth time of language , This time must be passed when formatting , There will be problems in other times .

原网站

版权声明
本文为[. fried eggs with tomatoes]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091135203792.html