码迷,mamicode.com
首页 > 其他好文 > 详细

3.7 两个时间差

时间:2018-03-22 01:51:22      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:def   时间   location   pack   AC   default   blog   sha   imp   


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 两个时间差

标签:def   时间   location   pack   AC   default   blog   sha   imp   

原文地址:https://www.cnblogs.com/zrdpy/p/8620866.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!