zoukankan      html  css  js  c++  java
  • 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
    ", t)
    	fmt.Printf("Second Default date is %v
    ", t2)
    
    	dur := t2.Sub(t)
    	fmt.Printf("The duration between t and t2 is %v
    ", dur)
    
    	dur = time.Since(t)
    	fmt.Printf("The duration between now and t is %v
    ", dur)
    
    	dur = time.Until(t)
    	fmt.Printf("The duration between t and now is %v
    ", 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
    */
    
    
  • 相关阅读:
    YAML序列样式
    YAML块标量头
    YAML字符流
    YAML语法字符
    YAML流程
    YAML集合和结构
    YAML缩进和分离
    YAML简介
    Git工作流程
    Git使用前配置
  • 原文地址:https://www.cnblogs.com/zrdpy/p/8620866.html
Copyright © 2011-2022 走看看