go和python的比较,获取当前时间是今年第几个星期
获取当前时间是今年的第几周
golang:
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() }
python:
import datetime year, week, day = datetime.datetime.now().isocalendar() print(week)
或者
import time time.strftime("%W")