时间:2021-06-11 08:06:40 | 栏目:Golang | 点击:次
实例如下所示:
package main import ( "fmt" "time" ) func main() { timeStr := time.Now().Format("2006-01-02") fmt.Println(timeStr) //使用Parse 默认获取为UTC时区 需要获取本地时区 所以使用ParseInLocation t, _ := time.ParseInLocation("2006-01-02 15:04:05", timeStr+" 23:59:59", time.Local) t2, _ := time.ParseInLocation("2006-01-02", timeStr, time.Local) fmt.Println(t.Unix() + 1) fmt.Println(t2.AddDate(0, 0, 1).Unix()) }