需求是这样的,有一个在日志中的时间,格式化为%Y%m%d-%H%M%S格式的,那现在想比较这个时间与当前时间差值是否大于一天,这个应该怎么做呢?设计到日期的减法运算,首先先
man date
来看一下用法吧。
DATE(1) User Commands DATE(1)
NAME
date - print or set the system date and time
- 打印或设置系统日期和时间
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’
显示字符串表示的时间,字符串不能是“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. Example: Mon, 07 Aug
2006 12:34:56 -0600
以RFC格式输出日期和时间,示例:Mon, 07 Aug 2006 12:34:56 -0600
--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.
Date and time components are separated by a single space:
2006-08-07 12:34: