Linux Date命令格式化时间zz

Linux Date命令格式化时间zz

上一篇 / 下一篇  2009-11-25 13:30:02 / 个人分类:program

查看( 556 ) / 评论( 0 ) / 评分( 0 / 0 )

Format Dates for Logs and Files

$ date "+%m%d%y %A,%B %d %Y %X"
061704 Thursday,June 17 2004 07:13:40 PM

$ date "+%m%d%Y"
06172004

$ date -d '1 day ago' "+%m%d%Y"
06162004

$ date -d '3 months 1 day 2 hour 15 minutes 2 seconds ago'

or to go into the future remove the “ago”

$ date -d '3 months 1 day 2 hour 15 minutes 2 seconds '

Also the following works:

$ date -d '+2 year +1 month -1 week +3 day -8 hour +2 min -5 seconds'

Quick question: If there are 100,000,000 stars in the visible sky, and you can
count them, round the clock, at a rate of a star per second starting now, when
would you finish counting? Would you still be alive?

$ date -d '+100000000 seconds'

Sooner than you think!

This can be assigned to variables

$ mdate=`date -d '3 months 1 day 2 hour 15 minutes 2 seconds ' "+%m%d%Y_%A_%B_%D_%Y_%X" `
$ echo $mdate
09182004_Saturday_September_09/18/04_2004_09:40:41 PM
^---- Easy to sort ^-------^----- Easy to read

See TIP 28 below.

See TIP 87 when working with large delta time changes -40 years, or -200 years ago, or even
1,000,000 days into the future.

Also see (TIP 1) for working with time zones.

Convert Epoch Seconds to the Current Time. Note, some programs like Nagios list
epoch seconds. Here’s a way to do the conversion.

$ date -d "1970-01-01 1184521826 sec GMT"
Sun Jul 15 13:50:26 EDT 2007

The above command converts 1184521826 to the current time.

Linux / Unix Command:date

http://linux.about.com/od/commands/l/blcmdl1_date.htm

AKPC_IDS += "549,";

你可能感兴趣的:(Date,linux,unix,command,nagios,variables)