zoukankan      html  css  js  c++  java
  • go time类操作

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

  • 相关阅读:
    133
    132
    131
    130
    129
    128
    2019.10.16考试解题报告
    2019.10.15考试解题报告
    洛谷 P1352 没有上司的舞会
    2019.10.13考试解题报告
  • 原文地址:https://www.cnblogs.com/zlingh/p/8710549.html
Copyright © 2011-2022 走看看