package main
import (
"fmt"
"time"
)
func main() {
datetime := "20210401" //待转化为时间戳的字符串
fmt.Println(GetWeek(datetime))
//
////时间戳转化为日期
//datetime = time.Unix(timestamp, 0).Format(timeLayout)
//fmt.Println(datetime)
}
func GetWeek(datetime string) (y, w int) {
timeLayout := "20060102"
loc, _ := time.LoadLocation("Local")
tmp, _ := time.ParseInLocation(timeLayout, datetime, loc)
return tmp.ISOWeek()
}
输出的样子是这样的
有疑问加站长微信联系(非本文作者)