golang 獲取上一個月的開始 結束 時間戳


  
func (s *Service) getLastMonthStartEnd() (int64, int64) {
now := time.Now()
lastMonthFirstDay := now.AddDate(0, -1, -now.Day()+1)
lastMonthStart := time.Date(lastMonthFirstDay.Year(), lastMonthFirstDay.Month(), lastMonthFirstDay.Day(), 0, 0, 0, 0, now.Location()).Unix()
lastMonthEndDay := lastMonthFirstDay.AddDate(0, 1, -1)
lastMonthEnd := time.Date(lastMonthEndDay.Year(), lastMonthEndDay.Month(), lastMonthEndDay.Day(), 23, 59, 59, 0, now.Location()).Unix()
return lastMonthStart, lastMonthEnd
}
lastMonthStart, lastMonthEnd := s.getLastMonthStartEnd()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM