3.7 两个时间差

Posted cucy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了3.7 两个时间差相关的知识,希望对你有一定的参考价值。


package main

import (
    "fmt"
    "time"
)

func main() {

    l, err := time.LoadLocation("Asia/Shanghai")
    if err != nil {
        panic(err)
    }

    t := time.Date(2000, 1, 1, 0, 0, 0, 0, l)
    t2 := time.Date(2000, 1, 3, 0, 0, 0, 0, l)
    fmt.Printf("First Default date is %v\n", t)
    fmt.Printf("Second Default date is %v\n", t2)

    dur := t2.Sub(t)
    fmt.Printf("The duration between t and t2 is %v\n", dur)

    dur = time.Since(t)
    fmt.Printf("The duration between now and t is %v\n", dur)

    dur = time.Until(t)
    fmt.Printf("The duration between t and now is %v\n", dur)

}

/*
First Default date is 2000-01-01 00:00:00 +0800 CST
Second Default date is 2000-01-03 00:00:00 +0800 CST
The duration between t and t2 is 48h0m0s
The duration between now and t is 159720h29m17.845253s
The duration between t and now is -159720h29m17.845256s
*/

以上是关于3.7 两个时间差的主要内容,如果未能解决你的问题,请参考以下文章

这两个代码片段有啥区别?

这两个代码片段之间有区别吗?如果有,那又如何? [复制]

Android 使用两个不同的代码片段获取当前位置 NULL

javascript高级程序设计-3.7 函数

带有两个列表片段的可滚动布局

显示 ActionBar 选项卡的两个片段