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")

相关文章:

  • 2022-01-16
  • 2021-09-29
  • 2021-11-23
  • 2021-12-16
  • 2021-11-05
猜你喜欢
  • 2021-11-24
  • 2021-10-31
  • 2022-12-23
  • 2022-03-07
  • 2021-10-28
  • 2021-10-03
  • 2022-12-23
相关资源
相似解决方案