Go語言:求兩個日期相差的天數

package main

import (
	"fmt"
	"time"
)

func main(){
	current:=time.Now().Unix()  

	fmt.Println(current)

	BeforeDate:="2019-09-01 15:48:00"
	loc, _ := time.LoadLocation("Local")    //獲取時區  
	tmp, _ := time.ParseInLocation("2006-01-02 15:04:05", BeforeMoth, loc) 
	timestamp := tmp.Unix()    //轉化爲時間戳 類型是int64
	
	fmt.Println(timestamp)

	res:=(current-timestamp)/86400 //相差值

    fmt.Println(res) 
}
相關文章
相關標籤/搜索