当前位置: 技术问答>linux和unix
关于date时间格式化的问题!!!
来源: 互联网 发布时间:2016-09-29
本文导语: 一直不是很会用date命令去格式化时间,不是很清楚那些格式的时间可以用date命令去格式化。。。 下面是我遇到的一个问题: 1)我需要将02 09 10 13 00 这个时间格式化,来和系统当前时间(201009181540)做比较,该...
一直不是很会用date命令去格式化时间,不是很清楚那些格式的时间可以用date命令去格式化。。。
下面是我遇到的一个问题:
1)我需要将02 09 10 13 00 这个时间格式化,来和系统当前时间(201009181540)做比较,该怎么使用date命令
2)另外date命令还能格式化哪些格式的时间。。
3)假如我将02 09 10 13 00自己拼装成字符串201009021300,为什么在和系统当前时间(201009181540)作比较的时候出现invalid date。。
希望高手解答!!!
下面是我遇到的一个问题:
1)我需要将02 09 10 13 00 这个时间格式化,来和系统当前时间(201009181540)做比较,该怎么使用date命令
2)另外date命令还能格式化哪些格式的时间。。
3)假如我将02 09 10 13 00自己拼装成字符串201009021300,为什么在和系统当前时间(201009181540)作比较的时候出现invalid date。。
希望高手解答!!!
|
`--date=DATESTR'
Display the date and time specified in DATESTR instead of the
current date and time. DATESTR can be in almost any common
format. It can contain month names, time zones, `am' and `pm',
`yesterday', etc. For example, `--date="2004-02-27
14:19:13.489392193 +0530"' specifies the instant of time that is
489,392,193 nanoseconds after February 27, 2004 at 2:19:13 PM in a
time zone that is 5 hours and 30 minutes east of UTC.
* To print the date of the day before yesterday:
date --date='2 days ago'
* To print the date of the day three months and one day hence:
date --date='3 months 1 day'
* To print the day of year of Christmas in the current year:
date --date='25 Dec' +%j
其它
date -d"-1 day"
date -d"1 day ago"
date -d 1may
date --date='1970-01-01 00:02:00'
date -d '1970-01-01 UTC 946684800 seconds'
|
SYNOPSIS
date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
DESCRIPTION
Display the current time in the given FORMAT, or set the system date.
-d, --date=STRING
display time described by STRING, not 。ョnow。ッ
-f, --file=DATEFILE
like --date once for each line of DATEFILE
-r, --reference=FILE
display the last modification time of FILE
-R, --rfc-2822
output date and time in RFC 2822 format
--rfc-3339=TIMESPEC
output date and time in RFC 3339 format. TIMESPEC=。ョdate。ッ, 。ョsec-
onds。ッ, or 。ョns。ッ for date and time to the indicated precision.
-s, --set=STRING
set time described by STRING
-u, --utc, --universal
print or set Coordinated Universal Time
--help display this help and exit
--version
output version information and exit
FORMAT controls the output. The only valid option for the second form
specifies Coordinated Universal Time. Interpreted sequences are:
%% a literal %
%a locale。ッs abbreviated weekday name (e.g., Sun)
%A locale。ッs full weekday name (e.g., Sunday)
%b locale。ッs abbreviated month name (e.g., Jan)
%B locale。ッs full month name (e.g., January)
%c locale。ッs date and time (e.g., Thu Mar 3 23:05:25 2005)
%C century; like %Y, except omit last two digits (e.g., 21)
%d day of month (e.g, 01)
%D date; same as %m/%d/%y
%e day of month, space padded; same as %_d
%F full date; same as %Y-%m-%d
%g last two digits of year of ISO week number (see %G)
%G year of ISO week number (see %V); normally useful only with %V
%h same as %b
%H hour (00..23)
%I hour (01..12)
%j day of year (001..366)
%k hour ( 0..23)
%l hour ( 1..12)
%m month (01..12)
%M minute (00..59)
%n a newline
%N nanoseconds (000000000..999999999)
%p locale。ッs equivalent of either AM or PM; blank if not known
%P like %p, but lower case
%r locale。ッs 12-hour clock time (e.g., 11:11:04 PM)
%R 24-hour hour and minute; same as %H:%M
%s seconds since 1970-01-01 00:00:00 UTC
%S second (00..60)
%t a tab
%T time; same as %H:%M:%S
%u day of week (1..7); 1 is Monday
%U week number of year, with Sunday as first day of week (00..53)
%V ISO week number, with Monday as first day of week (01..53)
%w day of week (0..6); 0 is Sunday
%W week number of year, with Monday as first day of week (00..53)
%x locale。ッs date representation (e.g., 12/31/99)
%X locale。ッs time representation (e.g., 23:13:48)
%y last two digits of year (00..99)
%Y year
%z +hhmm numeric timezone (e.g., -0400)
%:z +hh:mm numeric timezone (e.g., -04:00)
%::z +hh:mm:ss numeric time zone (e.g., -04:00:00)
%:::z numeric time zone with : to necessary precision (e.g., -04,
+05:30)
%Z alphabetic time zone abbreviation (e.g., EDT)