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

  • 相关阅读:
    C/C++之文件打开方式差别
    C/C++获取文件大小
    dedecms使用
    TCP/IP概念简述
    protobuf新增message报错:类型已存在
    亚马逊MWS开发套路演示
    请求MWS报错401:Access Denied
    敏捷开发
    过滤器和拦截器的区别
    防盗链
  • 原文地址:https://www.cnblogs.com/zlingh/p/8710549.html
Copyright © 2011-2022 走看看