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
  • 相关阅读:
    做接口测试最重要的知识点
    HTTP和HTTPS区别
    UVA, 686 Goldbach's Conjecture (II)
    UVA, 543 Goldbach's Conjecture
    UVA, 580 Critical Mass
    UVA, 900 Brick Wall Patterns
    UVA, 11000 Bee
    UVA, 10079 Pizza Cutting
    C++ 向量<vector>的学习
    jenkins入门
  • 原文地址:https://www.cnblogs.com/hcy-fly/p/8309076.html
Copyright © 2011-2022 走看看