zoukankan      html  css  js  c++  java
  • 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)
    }
  • 相关阅读:
    PHP生成PDF并转换成图片爬过的坑
    PHAR系列之导言
    Linux学习之路(三)Shell脚本初探
    Linux学习之路(二)
    php 隐藏手机号中间几位
    tp 递归菜单列表【树状】
    php导出excel封装类
    php 导出Excel表格
    php字符串之翻转单词顺序列
    laravel实现跳转其他控制器
  • 原文地址:https://www.cnblogs.com/xingchong/p/15746022.html
Copyright © 2011-2022 走看看