免费注册 查看新帖 |

Chinaunix

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

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

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

论坛徽章:
0
2 [报告]
发表于 2008-09-26 15:29 |只看该作者
这个要写shell了

论坛徽章:
0
3 [报告]
发表于 2008-09-26 15:31 |只看该作者
get_one_day_before_specified_date()
{
#get the command line input(date month & year)
day=$1
month=$2
year=$3

# if it is the first day of the month
if [ $day -eq 01 ]
then
# if it is the first month of the year
if [ $month -eq 01 ]
then
# make the month as 12
month=12

# deduct the year by one
year=`expr $year - 1`
else
# deduct the month by one
month=`expr $month - 1`
fi

# use cal command, discard blank lines,
# take last field of last line,
# first awk command is used to get the
# last useful line of the calendar cmd,
# second awk command is used to get the
# last field of this last useful line,
# NF is no. of fields,
# $NF is value of last field

day=`cal $month $year | awk 'NF != 0{ last = $0 }; END{ print last }' | awk '{ print $NF }'`
else
# deduct the day by one
day=`expr $day - 1`
fi

# echo $year$month$day
# year_2dig=`echo $year|awk '{print substr($0,3)}'`
echo $year$month$day
}

YEAR_T=`date +%Y`;
MONTH_T=`date +%m`;
DAY_T=`date +%d`;

YESTERDAY=`get_one_day_before_specified_date $DAY_T $MONTH_T $YEAR_T`;


DATE=$YESTERDAY

可以参考上面的

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

论坛徽章:
0
5 [报告]
发表于 2008-09-26 19:42 |只看该作者
谢谢3、4楼的大侠们

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

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP