在 Unix 中获取昨天的日期 - KSH 脚本
下面的命令用于在 HP UX 上的 Unix Ksh 中获取昨天的日期
DATE_STAMP=`TZ=CST+24 date +%m/%d/%Y`
有人可以让我知道上面命令中的“CST + 24 date”有什么作用吗?
The below command is used for getting the yerterdays date in Unix Ksh on HP UX
DATE_STAMP=`TZ=CST+24 date +%m/%d/%Y`
Can somebody let me know what does "CST + 24 date " in above command do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该命令将时区设置为 CST+24 并返回该时区的日期。
如果你正在寻找一个命令来找出昨天的日期,你最好使用 TZ 技巧,尤其是。如果您所在的时区遵守 DST。
使用 perl oneliner 代替。
只是对您的命令的猜测 - 由于昨天在 CST+24 时区,该命令返回昨天的日期,如果您使用 CST-24,它会返回明天的日期,因为该日期会转换为 CST-24 时区的明天日期。
That command sets the timezone to CST+24 and returns the date in that timezone.
if you are looking for a command to find out yesterday's date, you are better of using the TZ trick esp. if you are in a timezone that observes DST.
use perl one liner instead.
Just a guess on your command - since its yesterday at CST+24 timezone the command returns yesterday's date and if you use CST-24, it retunrs tomorrow's date since the date translates to tomorrows date at CST-24 timezone.
VARIABLE=VALUE COMMAND
表示您将环境变量VARIABLE
设置为VALUE
但不持久,仅针对执行的命令COMMAND.
在您的示例中,这意味着:执行
date
命令,并将环境变量TZ
设置为CST+24
(即中部标准时间加 24 小时) )。VARIABLE=VALUE COMMAND
means that you set the environment variableVARIABLE
toVALUE
but not persistent but only for the executed commandCOMMAND
.In your example that means: Execute the
date
command with the environment variableTZ
set toCST+24
(which is Central Standard Time plus 24 hours).查看此页面 http://www.kodkast .com/blogs/unix-shell-scripting/how-to-get-yesterdays-date 在这里您可以找到昨天的日期以及 unix shell 脚本中的任何其他先前日期。
Check out this page http://www.kodkast.com/blogs/unix-shell-scripting/how-to-get-yesterdays-date where you can find out yesterday's date as well as any other previous date in unix shell scripting.