• Go time模块


    time模块处理和时间相关的内容

     获取其他日期信息

     使用 time.Format格式化时间

     可以直接引用的时间常量

     Sleep用来等待一段时间

    转成int64类型,进行加减运算

     一个小练习:统计程序运行时间

    package main
    
    import (
        "strconv"
        "time"
        "fmt"
    )
    
    func test() {
        str := ""
        for i :=0; i<100000; i++{
            str += strconv.Itoa(i)
        }
    }
    func main() {
    
        var now time.Time = time.Now()
        fmt.Println(now)
        fmt.Println(now.Year())
        fmt.Println(now.Month())
        fmt.Println(int(now.Month()))
        fmt.Println(now.Day())
        fmt.Println(now.Hour())
        fmt.Println(now.Minute())
        fmt.Println(now.Second())
    
        fmt.Println(now.Format("2006-01-02 15:04:05"))
    
        start := time.Now()
        fmt.Println("开始执行时间",start)
        test()
        end := time.Now()
        fmt.Println("结束执行时间",end)
        cost := end.Unix() - start.Unix()
        fmt.Println("总计执行时间",cost,"秒")
    }
    统计程序运行时间
  • 相关阅读:
    隐式类型转换
    STL::allocator rebind
    Proxy Class(代理类)
    C++ 没有合适的默认构造函数(无参数构造函数)
    E
    C
    Multiplication Puzzle POJ
    Brackets POJ
    Halloween Costumes LightOJ
    ACwing 139. 回文子串的最大长度(二分+Hash)
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/14011552.html
Copyright © 2020-2023  润新知