zoukankan      html  css  js  c++  java
  • Go开发之路 -- 时间和日期类型

    time包

    time.Time类型, 用来表示时间

    获取当前时间, now := time.Now()

    time.Duration() 用来表示纳秒

    时间类型的格式化

    now := time.Now()
    // 记住这个时间
    fmt.Println(now.Format("2006/1/02 15:04"))
    
    fmt.Println(now.Format("1/02/2006 15:04"))
    
    fmt.Println(now.Format("2006/1/02"))
    // 写一个程序, 获取当前时间,并格式化成 2019/03/31 08:05:00 形式
    
    package main
    
    import (
        "fmt"
        "time"
    )
    
    func main(){
        now := time.Now()    // 获取当前时间
    
        // 格式化
        fmt.Println(now.Format("2006/01/02 15:04:05"))  // 这里的时间不能变,必须是这个时间,才能正确显示当前时间
    }
    练习 6
    // 写一个程序, 统计一段代码的执行耗时, 单位精确到微妙
    
    package main
    
    import (
        "fmt"
        "time"
    )
    
    func test() {
        time.Sleep(time.Millisecond * 100)    // 微妙
    }
    
    func main(){
        start := time.Now().UnixNano()    // 纳秒
        test()
        end := time.Now().UnixNano()
    
        fmt.Printf("耗时: %d us
    ", (end - start) / 1000)
    }
    练习 7
  • 相关阅读:
    云网站 SEO
    GraphQL 开发原则
    软件秘钥实现
    删除文件
    GUI 桌面程序开发
    chcon SeLinux
    正确使用 cookie 的 path
    struts 2用DomainModel接收参数
    Struts 2动态调用方法(DMI)
    struts 2actionwildcard 通配符配置
  • 原文地址:https://www.cnblogs.com/lpgit/p/10632797.html
Copyright © 2011-2022 走看看