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)
    }
  • 相关阅读:
    在ASP.Net和IIS中删除不必要的HTTP响应头
    Json对象与Json字符串互转
    Jquery ajax传递复杂参数给WebService
    HTTP的KeepAlive是开启还是关闭?
    MQ产品比较-ActiveMQ-RocketMQ
    RocketMQ(7)——通信协议
    mq使用经验
    mq
    RocketMQ
    发送短信验证码实现方案
  • 原文地址:https://www.cnblogs.com/xingchong/p/15746022.html
Copyright © 2011-2022 走看看