使用以下代码,我可以在Linux中来回滚动。
date -s 'tomorrow'
date -s 'yesterday'
我想做同样的事情但跳过周末。
答案 0 :(得分:1)
以下为您提供下一个工作日(bash
):
if [[ $( date +%u ) -eq 5 ]] ; then date --date="next Monday" ; else date --date="next day" ; fi
答案 1 :(得分:1)
此脚本将日期设置为下一个工作日。在预先警告这些脚本消除周末跳过的时间之前。此外,它们不能移植到有限的shell,如busybox。
week_day=$(date +%w) #get the week day as a number from 0
if [[ $week_day == 5 || $week_day == 6 ]] #check to see if it is Fri or Sat
then date -s 'next monday' #if it is Fri or Sat, the set day to next monday
else date -s tomorrow #it is a different day of the week, go to the next day
fi
最后一周
week_day=$(date +%w) #get the week day as a number from 0 to 6 starting with 0 as Sunday
if [[ $week_day == 0 || $week_day == 1 ]] #check to see if it is Sun or Mon
then date -s 'last friday' #if it is Sun or Mon, the set day to last friday
else date -s yesterday #it is a different day of the week, go to yesterday
fi
答案 2 :(得分:0)
if [[ $( date +%u ) = 5 ]] ; then date --set="+3 days" ; else date --set="+1 days" ; fi
if [[ $( date +%u ) = 1 ]] ; then date --set="-3 days" ; else date --set="-1 days" ; fi