zlingh

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
fmt.Println(time.Now().Format("2006-01-02 15:04:05")) # 这是个奇葩,必须是这个时间点, 据说是go诞生之日, 记忆方法:6-1-2-3-4-5
# 2014-01-07 09:42:20

获取当前时间:time.Now()。返回time对象

获取当前时间戳:time.Now().Unix()

一、转time对象

1. 时间戳整数转time,Unix():time.Unix(time.Now().Unix(),0)

// Unix returns the local Time corresponding to the given Unix time,
// sec seconds and nsec nanoseconds since January 1, 1970 UTC.
// It is valid to pass nsec outside the range [0, 999999999].
// Not all sec values have a corresponding time value. One such
// value is 1<<63-1 (the largest int64 value).
func Unix(sec int64, nsec int64) Time {

2.字符串转time,Parse():time.Parse("20060102","20180328")

func Parse(layout, value string) (Time, error) {

二、time对象转其它

1. time转时间戳整数,Unix(): time.Now().Unix()

2.time转格式化的时间,Format:time.Now().Format("20060102")

posted on 2018-04-03 19:20  zlingh  阅读(217)  评论(0编辑  收藏  举报