`
guanjh
  • 浏览: 229439 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

计算一个日期是星期几

SUN 
阅读更多
get_whatdays()
{
# Sample input:20020703

year=`echo $1|cut -c1-4`
month=`echo $1|cut -c5-6`
day=`echo $1|cut -c7-8`
b=`cal $month $year|wc -l `
dow=`cal $month $year |awk '{for(i=1;i<=NF;i++){if($i=='$day'){if (NR=='"$b"'-1){print i-1}else{print 7-NF+i-1}}}}'`
#  Convert the numeric day of the week to a string
case $dow in
   0) print Sun ;;
   1) print Mon ;;
   2) print Tue ;;
   3) print Wed ;;
   4) print Thu ;;
   5) print Fri ;;
   6) print Sat ;;  
   *) print "wrong date" ;;
esac 
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics