免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4878 | 回复: 3
打印 上一主题 下一主题

请高手帮帮忙,AIX4.3中,怎样用date实现取系统日期的前1天? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-26 12:58 |只看该作者 |倒序浏览
大虾:\r\n我在命令行输入‘date +%Y-%m-%d’可得到结果‘2008-09-25’,但是我想要当前日期的前1天或前5天的日期,请问需要加什么参数?\r\n谢谢!

论坛徽章:
0
2 [报告]
发表于 2008-09-26 15:31 |只看该作者
get_one_day_before_specified_date()\r\n{\r\n#get the command line input(date month & year)\r\nday=$1\r\nmonth=$2\r\nyear=$3\r\n\r\n# if it is the first day of the month\r\nif [ $day -eq 01 ]\r\nthen\r\n# if it is the first month of the year\r\nif [ $month -eq 01 ]\r\nthen\r\n# make the month as 12\r\nmonth=12\r\n\r\n# deduct the year by one\r\nyear=`expr $year - 1`\r\nelse\r\n# deduct the month by one\r\nmonth=`expr $month - 1`\r\nfi\r\n\r\n# use cal command, discard blank lines,\r\n# take last field of last line,\r\n# first awk command is used to get the\r\n# last useful line of the calendar cmd,\r\n# second awk command is used to get the\r\n# last field of this last useful line,\r\n# NF is no. of fields,\r\n# $NF is value of last field\r\n\r\nday=`cal $month $year | awk \'NF != 0{ last = $0 }; END{ print last }\' | awk \'{ print $NF }\'`\r\nelse\r\n# deduct the day by one\r\nday=`expr $day - 1`\r\nfi\r\n\r\n# echo $year$month$day\r\n# year_2dig=`echo $year|awk \'{print substr($0,3)}\'`\r\necho $year$month$day\r\n}\r\n\r\nYEAR_T=`date +%Y`;\r\nMONTH_T=`date +%m`;\r\nDAY_T=`date +%d`;\r\n\r\nYESTERDAY=`get_one_day_before_specified_date $DAY_T $MONTH_T $YEAR_T`;\r\n\r\n\r\nDATE=$YESTERDAY\r\n\r\n可以参考上面的

论坛徽章:
0
3 [报告]
发表于 2008-09-26 19:00 |只看该作者
perl -e \"use POSIX qw(strftime); print strftime \'%Y%m%d\' , localtime( time()-3600*24) \"

论坛徽章:
0
4 [报告]
发表于 2008-09-28 10:06 |只看该作者
改下时区就好了吖\r\nTZ=TZ+1 这样子\r\n不过最后要再改回来 要不影响其他东西\r\nTZ=TZ
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP