其中time.parse格式改变后,未发生变化
再换,结果未变:
截取取小时:
1
|
test, err := time.Parse( "2006-01-02 15" , "2013-05-13 13" )
|
截取到分钟:
截取到秒:
随着截取位置的不同,通过补零设置
2023-12-05 17:44:58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
package
main
import
(
"fmt"
"time"
) func main() { test, err := time.Parse( "2006-01-02" , "2013-01-12" )
if
err != nil {
panic(err)
}
fmt.Println(test)
} |
[ `run` | done: 4.533945ms ] 2013-01-12 00:00:00 +0000 UTC
其中time.parse格式改变后,未发生变化
1
|
test, err := time.Parse( "2006/01/02" , "2013/01/12" )
|
[ `run` | done: 1.499388ms ] 2013-01-12 00:00:00 +0000 UTC
再换,结果未变:
1
|
test, err := time.Parse( "01/02/2006" , "01/12/2013" )
|
[ `run` | done: 1.471152ms ] 2013-01-12 00:00:00 +0000 UTC
截取取小时:
1
|
test, err := time.Parse( "2006-01-02 15" , "2013-05-13 13" )
|
截取到分钟:
1
|
test, err := time.Parse( "2006-01-02 15:04" , "2013-05-13 10:30" )
|
[ `run` | done: 1.414665ms ] 2013-05-13 10:30:00 +0000 UTC
截取到秒:
1
|
test, err := time.Parse( "2006-01-02 15:04:05" , "2013-05-13 10:30:03" )
|
[ `run` | done: 1.554238ms ] 2013-05-13 10:30:03 +0000 UTC
随着截取位置的不同,通过补零设置