本文csdn博文链接:http://blog.youkuaiyun.com/screscent/article/details/53409708
本文QQ空间链接:http://user.qzone.qq.com/29185807/blog/1478769778
golang中time库中
格式化时间用Time.Format,解析时间用time.Parse。
func Parse(layout, value string) (Time, error)
func (t Time) Format(layout string) string
其中layout的格式为
月份 1,01,Jan,January
日 2,02,_2
时 3,03,15,PM,pm,AM,am
分 4,04
秒 5,05
年 06,2006
周几 Mon,Monday
时区时差表示 -07,-0700,Z0700,Z07:00,-07:00,MST
时区字母缩写 MST
例如
package main
import (
"fmt"
"time"
)
func main() {
str := "[08/Nov/2016:18:31:21 +0800]"
t, _ := time.Parse("[02/Jan/2006:15:4:5 -0700]",str)
fmt.Println(t)
}
结果
2016-11-08 18:31:21 +0800 CST
龚浩华
qq 29185807 月牙寂
2016年11月10日

本文介绍了Golang中处理时间戳的两种主要方法:使用`Time.Format`进行时间格式化,以及使用`time.Parse`进行时间解析。通过示例展示了如何定义layout格式,如`2006年01月02日`,并提供了相关链接以供深入阅读。
最低0.47元/天 解锁文章
3794

被折叠的 条评论
为什么被折叠?



