免费注册 查看新帖 |

Chinaunix

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

如何显示前一天日期 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-07-19 15:38 |只看该作者 |倒序浏览
如果,今天是JUL 19,我想要显示JUL 18,怎么做?

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
2 [报告]
发表于 2005-07-19 15:54 |只看该作者

如何显示前一天日期

如果是linux的话,可以:
date "+%b %d" -d'-1 day'

论坛徽章:
0
3 [报告]
发表于 2005-07-19 16:37 |只看该作者

如何显示前一天日期

#date -d  'yesterday'

具体应用需求,自己再加参数

论坛徽章:
0
4 [报告]
发表于 2005-07-19 16:52 |只看该作者

如何显示前一天日期

懒得研究DATE了,自己写了个SHELL


#Created by ICE
day=`date '+%e'`
mon=`date '+%m'`
mon=`expr $mon + 0`

case "$mon" in

3)
        bday=28
        ;;
2|4|6|8|9|11|1)
        bday=31
        ;;
*)
        bday=30
        ;;
esac

if test `expr $day - 1` -eq 0
        then
                if test `expr $mon - 1` -eq 0
                        then
                                mon=12
                                echo $mon $bday
                        else
                                mon=`expr $mon - 1`
                                echo $mon $bday
                fi
        else
                bday=`expr $day - 1`
                echo $mon $bday
fi

论坛徽章:
0
5 [报告]
发表于 2005-07-19 17:43 |只看该作者

如何显示前一天日期

CurYear=`date +%Y`
CurMonth=`date +%m`
CurDay=`date +%d`


GetYear="$CurYear"
GetMonth="$CurMonth"
GetDay="`expr $CurDay - 1`"


if [ "$GetDay" -le 0 ] ; then

        GetMonth=`expr $CurMonth - 1`

        if [ "$GetMonth" -le 0 ] ; then

                GetYear=`expr $CurYear - 1`
                GetMonth=12

        fi

        case "$GetMonth"
        in
                1|3|5|7|8|10|12)

                        GetDay=31;;
                4|6|9|11)

                        GetDay=30;;
                2)

                        if [ `expr "$CurYear" % 400` -eq 0 ] ; then

                                GetDay=29
                        elif [ `expr "$CurYear" % 4` -eq 0 -a `expr "$CurYear" % 100` -ne 0 ] ; then

                                GetDay=29
                        else

                                GetDay=28
                        fi
        esac

fi

if [ `echo "$GetMonth" | wc -m` -ne 3 ] ; then

        GetMonth=0$GetMonth
fi

if [ `echo "$GetDay" | wc -m` -ne 3 ] ; then

        GetDay=0$GetDay
fi
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP