golang 通过ISOWeek翻转得到周的日期时间

前端之家收集整理的这篇文章主要介绍了golang 通过ISOWeek翻转得到周的日期时间前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
func firstDayOfISOWeek(year int,week int,timezone *time.Location) time.Time {
    date := time.Date(year,0,timezone)
    isoYear,isoWeek := date.ISOWeek()
    for date.Weekday() != time.Monday { // iterate back to Monday
        date = date.AddDate(0,-1)
        isoYear,isoWeek = date.ISOWeek()
    }
    for isoYear < year { // iterate forward to the first day of the first week
        date = date.AddDate(0,1)
        isoYear,isoWeek = date.ISOWeek()
    }
    for isoWeek < week { // iterate forward to the first day of the given week
        date = date.AddDate(0,isoWeek = date.ISOWeek()
    }
    return date
}
原文链接:https://www.f2er.com/go/188826.html

猜你在找的Go相关文章