golang 获取当前日期,月份第一天和最后一天

前端之家收集整理的这篇文章主要介绍了golang 获取当前日期,月份第一天和最后一天前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
now := time.Now()
    currentYear,currentMonth,_ := now.Date()
    currentLocation := now.Location()

    firstOfMonth := time.Date(currentYear,1,currentLocation)
    lastOfMonth := firstOfMonth.AddDate(0,-1)

    fmt.Println(firstOfMonth.Unix())
    fmt.Println(lastOfMonth.Unix())
    
    layout := "2006-01-02 15:04:05"
    loc,_:= time.LoadLocation("Asia/Chongqing")
    zero_day,_ := time.ParseInLocation(layout,"1949-10-01 00:00:00",loc)
原文链接:https://www.f2er.com/go/188931.html

猜你在找的Go相关文章