Home > Notes > SH获取昨天日期

SH获取昨天日期

Tue, 02 Feb 2010 02:15:06 +0800

区别于bash的sh获取昨天的日期

bash里使用 date -d "yesterday"就可以了,但sh里不行

我们用变换时区的办法获取:

> d=`TZ=$TZ+24 date "+%Y/%m/%d"`

> echo $d

2010/02/01

-----

但是,建议还是看一下date的用法。不同的环境可能有更好的办法

我在freebsd下,

date的用法如下

usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]
---

其中,参数-v可以进行这样的操作

> date -v-1d +%Y%m%d

20100201

> date -v-2d +%Y%m%d

20100131

Tag:SHELL
Hots
评论
发表评论:


  [TIPS:首次发表评论的朋友,需要验证]
Tags
Recent Post
Recent Comments
Links
Copyright Notes
You can reship all of these articles without permission but MUST mark the original link in your post. Please contact with me() if u have advice or other arrangements.
Copyright©2007-2011 lewphee.com All rights reserved.