• GO语言常用标准库03---time包


    package main
    
    import (
    	"fmt"
    	"time"
    )
    
    func main021() {
    	nowTime := time.Now()
    	fmt.Println(nowTime.Year())//2018
    	fmt.Println(nowTime.Month())//December
    	fmt.Println(nowTime.Day())//25
    	fmt.Println(nowTime.Date())//2018 December 25
    	fmt.Println(nowTime.Hour())//10
    	fmt.Println(nowTime.Minute())//26
    	fmt.Println(nowTime.Second())//?
    	fmt.Println(nowTime.Nanosecond())//?
    	fmt.Println(nowTime.Weekday())//Tuesday
    	fmt.Println(nowTime.YearDay())//359
    
    	//定义2019年元旦的Time对象
    	yuandanTime := time.Date(2019, time.January, 1, 0, 0, 0, 0, time.Now().Location())
    	fmt.Println(yuandanTime) //2019-01-01 00:00:00 +0800 CST
    
    	//计算当前时间距离2019年元旦的时间差
    	duration := nowTime.Sub(yuandanTime)
    	fmt.Println(duration)//-157h19m31.9387253s
    
    	//解析获得时间差Duration对象
    	duration, _ = time.ParseDuration("157h19m31.9387253s")
    
    	//将当前时间时间加上时间差获得新的时间对象
    	newTime := nowTime.Add(duration)
    	fmt.Println("newTime=",newTime)
    
    }
    
    /*计算中国成为大一统国家的历史长度*/
    func main() {
    	duration := time.Now().Sub(time.Date(-211, time.January, 1, 0, 0, 0, 0, time.Now().Location()))
    	fmt.Println(duration.String())
    
    	time.Now().Unix()
    }
    

      

  • 相关阅读:
    Model-Free Control
    Importance Sampling 重要性采样
    蓝桥 等差素数列(找最小公差)
    抽签
    放苹果(poj1664)
    BFS进阶题,水陆距离
    线段树的单点更新,求最大值(HDU1754)
    Balanced Lineup (自用线段树模板一)
    自用模板,树状数组
    线段树自用模板
  • 原文地址:https://www.cnblogs.com/yunweiqiang/p/11854126.html
Copyright © 2020-2023  润新知