zoukankan      html  css  js  c++  java
  • Go

    在编程中,程序员会经常使用到日期相关的函数,例如:统计某段代码执行花费的时间等等;
     
        1.时间和日期相关函数,都是在time包中;
                // 获取当前时间    
                now := time.Now()     
                // 输出结果:now=2020-11-09 18:29:17.9963558 +0800 CST m=+0.004987501 now type =time.Time                             
                fmt.Printf("now=%v now type =%T", now, now)
     
        2.// 通过now 来获取当前的年月日 时分秒    
            fmt.Printf("年=%v  ", now.Year())     
            fmt.Printf("月=%v  ", now.Month())  // 可以通过int 把英文强转为 int      
            fmt.Printf("月=%v  ", int(now.Month()))     
            fmt.Printf("日=%v  ", now.Day())     
            fmt.Printf("时=%v  ", now.Hour())     
            fmt.Printf("分=%v  ", now.Minute())     
            fmt.Printf("秒=%v  ", now.Second())
     
        3.// 也可以使用格式化输出    但是时间是固定的,格式可以调整
            fmt.Println(now.Format("2006-01-02 15:04:05"))     
            fmt.Println(now.Format("2006/01/02 15:04:05"))     
            fmt.Println(now.Format("2006-01-02"))     
            fmt.Println(now.Format("15:04:05"))
     
        4.时间常量结合休眠
            i := 0    
            for {         
                i ++         
                // time.Sleep(time.Second)  // 每隔1秒输出一个数字         
                time.Sleep(time.Millisecond * 100)  // 每隔0.1秒输出一个数字 即微妙 * 100 --> 0.1秒         
                fmt.Println(i)         
                if i > 100 {             
                    break         
                }     
            }
     
        5.时间戳Unix(秒数) / UnixNano(纳秒)
            fmt.Println("unix时间戳:", now.Unix(), "unixNano时间戳:", now.UnixNano())
     
     
  • 相关阅读:
    pandas 筛选指定行或者列的数据
    数据相关性分析方法
    导入sklearn 报错,找不到相关模块
    特征探索经验
    python 中hive 取日期时间的方法
    云从科技 OCR任务 pixel-anchor 方法
    五种实现左中右自适应布局方法
    vscode vue 代码提示
    js Object.create 初探
    webpack 加载css 相对路径 ~
  • 原文地址:https://www.cnblogs.com/guo-s/p/13954125.html
Copyright © 2011-2022 走看看