文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>aix环境下计算昨天日期的shell两例...

aix环境下计算昨天日期的shell两例...

时间:2010-08-03  来源:nsj820

1、 改变时区的方法

cat yesterday.sh

 aaa=`echo $TZ|sed 's/.*\(..\)/\1/'` aaa=`expr $aaa + 24` eval aaa=`echo $TZ|sed 's/..$/+$aaa/'` TZ=$aaa export TZ yy=`date +%Y` mm=`date +%m` dd=`date +%d` echo $yy$mm$dd

2、 遍历所有情况类似函数的方法

cat yesterday.sh

 #!/bin/bash # Var Declare #!/bin/sh # ydate: A Bourne shell script that # prints yestarday's date # Output Form: Month Day Year # Set the current month day and year. month=`date +%m` day=`date +%d` year=`date +%Y` # Add 0 to month. This is a # trick to make month an unpadded integer. month=`expr $month + 0` # Subtract one from the current day. day=`expr $day - 1` # If the day is 0 then determine the last # day of the previous month. if [ $day -eq 0 ]; then # Find the preivous month. month=`expr $month - 1` # If the month is 0 then it is Dec 31 of # the previous year. if [ $month -eq 0 ]; then month=12 day=31 year=`expr $year - 1` # If the month is not zero we need to find # the last day of the month. else case $month in 1|3|5|7|8|10|12) day=31;; 4|6|9|11) day=30;; 2) if [ `expr $year % 4` -eq 0 ]; then if [ `expr $year % 400` -eq 0 ]; then day=29 fi else day=28 fi ;; esac fi fi echo yesterday:$year-${month}-${day}

说明:方法1较简洁明了,代码清晰;方法2是一般写程序的方法。

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载