zoukankan      html  css  js  c++  java
  • go time包

    go time包

    /**
    * @Author: wsp
    * @Date: 2018/1/18 10:17
    * @Description:
     */
    package timeStudy
    
    import (
        "fmt"
        "time"
    )
    
    func TimeStudy1() {
    
        // 时间转string
        timeNow := time.Now()
        // 获取当前时间
        fmt.Println(timeNow)
        fmt.Println("=====================")
    
        // 格式化时间,格式必须为:2006-01-02 15:04:05
        format := timeNow.Format("2006-01-02 15:04:05")
        fmt.Println(format)
    
        // string 转时间 layout:格式必须为:2006-01-02 15:04:05
        t, _ := time.Parse("2006-01-02 15:04:05", "2014-06-15 08:37:18")
        fmt.Println("========================")
        fmt.Println(t)
    
        fmt.Println("========================")
        // 判断时间的前后
        fmt.Println(t.Before(timeNow))
        fmt.Println(t.After(timeNow))
    
        // 返回时间戳,长度为10
        fmt.Println("========================")
        fmt.Println(time.Now().Unix())
    
        // 自定义时间对象
        fmt.Println("========================")
        fmt.Println(time.Date(2017, 02, 27, 20, 20, 20, 20, time.Local))
    
        // 字符串转时间戳
        fmt.Println("========================")
        fmt.Println(t.Unix())
    
        //timeNow1 := time.Now(),获取某个时间与当前时间差
        fmt.Println("========================")
        fmt.Println(time.Since(timeNow))
    
        fmt.Println("========================")
    }

    运行结果:

    2018-01-18 10:51:49.145745 +0800 CST
    =====================
    2018-01-18 10:51:49
    ========================
    2014-06-15 08:37:18 +0000 UTC
    ========================
    true
    false
    ========================
    1516243909
    ========================
    2017-02-27 20:20:20.00000002 +0800 CST
    ========================
    1402821438
    ========================
    35.0245ms
    ========================
    1h0m0s
    
    Process finished with exit code 0
  • 相关阅读:
    redis系列之------过期策略
    总结与期盼
    服务不可用排查思路
    Spring Boot Starters到底怎么回事?
    redis系列之------主从复制
    redis系列之------对象
    redis系列之------数据库
    DirectX11 With Windows SDK--00 目录
    DirectX11 With Windows SDK--34 位移贴图
    DirectX11 With Windows SDK--33 曲面细分阶段(Tessellation)
  • 原文地址:https://www.cnblogs.com/hcy-fly/p/8309076.html
Copyright © 2011-2022 走看看