在 Unix 中获取昨天的日期 - KSH 脚本

发布于 2024-11-18 04:53:27 字数 152 浏览 1 评论 0原文

下面的命令用于在 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不喜欢何必死缠烂打 2024-11-25 04:53:27

该命令将时区设置为 CST+24 并返回该时区的日期。

如果你正在寻找一个命令来找出昨天的日期,你最好使用 TZ 技巧,尤其是。如果您所在的时区遵守 DST。

使用 perl oneliner 代替。

#this takes local time and substracts a day(24*60*60 seconds) and formats the time.
echo `perl -e 'use POSIX; print strftime "%m/%d/%Y%", localtime time-86400;'` 

只是对您的命令的猜测 - 由于昨天在 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.

#this takes local time and substracts a day(24*60*60 seconds) and formats the time.
echo `perl -e 'use POSIX; print strftime "%m/%d/%Y%", localtime time-86400;'` 

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.

沫尐诺 2024-11-25 04:53:27

VARIABLE=VALUE COMMAND 表示您将环境变量 VARIABLE 设置为 VALUE 但不持久,仅针对执行的命令 COMMAND.

在您的示例中,这意味着:执行 date 命令,并将环境变量 TZ 设置为 CST+24(即中部标准时间加 24 小时) )。

VARIABLE=VALUE COMMAND means that you set the environment variable VARIABLE to VALUE but not persistent but only for the executed command COMMAND.

In your example that means: Execute the date command with the environment variable TZ set to CST+24 (which is Central Standard Time plus 24 hours).

天荒地未老 2024-11-25 04:53:27

查看此页面 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文