• Go——关于Time包


    需要转换毫秒值 Milliseconds

    但包里面单单没有提供毫秒值的装换呢? 

    Go 语言的设计者希望我有更多的选择,而不只是将毫秒值转换成某种单独的内建类型。

    在 Time 包中,定义有一个名为 Duration 的类型和一些辅助的常量。

    当我们再次查看Duration类型的定义,可以发现Duration类型汇总基本单位时间是纳秒(Nanosecond),所以讲一个表示10毫秒的Durantion类型对象转换为int64类型时,实际上得到的是10,000,000。

    // Milliseconds returns the duration as a floating point number of Milliseconds.
    // add by chong
    func (d Duration) Milliseconds() float64 {
        milli := d / Millisecond
        nsec := d % Millisecond
        return float64(milli) + float64(nsec)/1e6
    }
    // Seconds returns the duration as a floating point number of seconds.
    func (d Duration) Seconds() float64 {
        sec := d / Second
        nsec := d % Second
        return float64(sec) + float64(nsec)/1e9
    }
    
    // Minutes returns the duration as a floating point number of minutes.
    func (d Duration) Minutes() float64 {
        min := d / Minute
        nsec := d % Minute
        return float64(min) + float64(nsec)/(60*1e9)
    }
    
    // Hours returns the duration as a floating point number of hours.
    func (d Duration) Hours() float64 {
        hour := d / Hour
        nsec := d % Hour
        return float64(hour) + float64(nsec)/(60*60*1e9)
    }
  • 相关阅读:
    C语言第十一讲,预处理命令.
    C语言第十讲,枚举类型简单说明
    C语言第九讲,结构体
    C语言第八讲,指针*
    C语言第七讲,函数入门.
    C语言第六讲,数组
    C语言第五讲,语句 顺序循环选择.
    C语言第四讲,typedef 关键字,以及作用域
    C语言第三讲,基本数据类型
    64位内核第二讲,进程保护之对象钩子
  • 原文地址:https://www.cnblogs.com/xingchong/p/15746022.html
Copyright © 2020-2023  润新知