Go计算两个时间差了几个工作日

最土的办法,就是模拟:

func calc_work_day(begin, end time.Time) int {
  var workDay = 0
  var curTime = begin
  for {
    if curTime.After(end) {
      break
    }
    if curTime.Weekday() == time.Saturday || curTime.Weekday() == time.Sunday {
      // skip
    } else {
      workDay++
    }
    curTime = curTime.Add(time.Hour * 24)
  }
  return workDay
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *