shell date 詳細用法 如date --date='1 month ago' '+%Y%m'
1.To print the date of the day before yesterday:
date --date='2 days ago'
2. To print the date of the day three months and one day hence:
date --date='3 months 1 day'
3. To print the day of year of Christmas in the current year:
date --date='25 Dec' +%j
4. To print the current full month name and the day of the month:
date '+%B %d'
But this may not be what you want because for the first nine days
of the month, the `%d' expands to a zero-padded two-digit field,
for example `date -d 1may '+%B %d'' will print `May 01'.
5. To print a date without the leading zero for one-digit days of the
month, you can use the (GNU extension) `-' flag to suppress the
padding altogether:
date -d 1may '+%B %-d
6. To print the current date and time in the format required by many
non-GNU versions of `date' when setting the system clock:
date +%m%d%H%M%Y.%S
7. To set the system clock forward by two minutes:
date --set='+2 minutes'
8. To print the date in RFC 2822 format, use `date --rfc-2822'. Here
is some example output:
Fri, 09 Sep 2005 13:51:39 -0700
9. To convert a date string to the number of seconds since the epoch
(which is 1970-01-01 00:00:00 UTC), use the `--date' option with
the `%s' format. That can be useful in sorting and/or graphing
and/or comparing data by date. The following command outputs the
number of the seconds since the epoch for the time two minutes
after the epoch:
date --date='1970-01-01 00:02:00 +0000' +%s
date --date='1970-01-01 00:02:00 +0000' +%s
120
If you do not specify time zone information in the date string,
`date' uses your computer's idea of the time zone when
interpreting the string. For example, if your computer's time
zone is that of Cambridge, Massachusetts, which was then 5 hours
(i.e., 18,000 seconds) behind UTC:
# local time zone used
date --date='1970-01-01 00:02:00' +%s
18120
10. If you're sorting or graphing dated data, your raw date values may
be represented as seconds since the epoch. But few people can
look at the date `946684800' and casually note "Oh, that's the
first second of the year 2000 in Greenwich, England."
date --date='2000-01-01 UTC' +%s
946684800
An alternative is to use the `--utc' (`-u') option. Then you may
omit `UTC' from the date string. Although this produces the same
result for `%s' and many other format sequences, with a time zone
offset different from zero, it would give a different result for
zone-dependent formats like `%z'.
date -u --date=2000-01-01 +%s
946684800
To convert such an unwieldy number of seconds back to a more
readable form, use a command like this:
11. local time zone used
date -d '1970-01-01 UTC 946684800 seconds' +"%Y-%m-%d %T %z"
1999-12-31 19:00:00 -0500
Often it is better to output UTC-relative date and time:
date -u -d '1970-01-01 946684800 seconds' +"%Y-%m-%d %T %z"
2000-01-01 00:00:00 +0000
date --date='2 days ago'
2. To print the date of the day three months and one day hence:
date --date='3 months 1 day'
3. To print the day of year of Christmas in the current year:
date --date='25 Dec' +%j
4. To print the current full month name and the day of the month:
date '+%B %d'
But this may not be what you want because for the first nine days
of the month, the `%d' expands to a zero-padded two-digit field,
for example `date -d 1may '+%B %d'' will print `May 01'.
5. To print a date without the leading zero for one-digit days of the
month, you can use the (GNU extension) `-' flag to suppress the
padding altogether:
date -d 1may '+%B %-d
6. To print the current date and time in the format required by many
non-GNU versions of `date' when setting the system clock:
date +%m%d%H%M%Y.%S
7. To set the system clock forward by two minutes:
date --set='+2 minutes'
8. To print the date in RFC 2822 format, use `date --rfc-2822'. Here
is some example output:
Fri, 09 Sep 2005 13:51:39 -0700
9. To convert a date string to the number of seconds since the epoch
(which is 1970-01-01 00:00:00 UTC), use the `--date' option with
the `%s' format. That can be useful in sorting and/or graphing
and/or comparing data by date. The following command outputs the
number of the seconds since the epoch for the time two minutes
after the epoch:
date --date='1970-01-01 00:02:00 +0000' +%s
date --date='1970-01-01 00:02:00 +0000' +%s
120
If you do not specify time zone information in the date string,
`date' uses your computer's idea of the time zone when
interpreting the string. For example, if your computer's time
zone is that of Cambridge, Massachusetts, which was then 5 hours
(i.e., 18,000 seconds) behind UTC:
# local time zone used
date --date='1970-01-01 00:02:00' +%s
18120
10. If you're sorting or graphing dated data, your raw date values may
be represented as seconds since the epoch. But few people can
look at the date `946684800' and casually note "Oh, that's the
first second of the year 2000 in Greenwich, England."
date --date='2000-01-01 UTC' +%s
946684800
An alternative is to use the `--utc' (`-u') option. Then you may
omit `UTC' from the date string. Although this produces the same
result for `%s' and many other format sequences, with a time zone
offset different from zero, it would give a different result for
zone-dependent formats like `%z'.
date -u --date=2000-01-01 +%s
946684800
To convert such an unwieldy number of seconds back to a more
readable form, use a command like this:
11. local time zone used
date -d '1970-01-01 UTC 946684800 seconds' +"%Y-%m-%d %T %z"
1999-12-31 19:00:00 -0500
Often it is better to output UTC-relative date and time:
date -u -d '1970-01-01 946684800 seconds' +"%Y-%m-%d %T %z"
2000-01-01 00:00:00 +0000
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29446986/viewspace-1428178/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- date_format(date,frm) 詳解ORM
- JavaScript 的 Date 最詳細解讀JavaScript
- date 命令詳解
- How to Convert a Date Time to “X minutes ago” in C# zGoC#
- linux下 date的用法Linux
- linux下date命令用法Linux
- mysql DATE_ADD DATE_SUBMySql
- js Date.now()函式用法JS函式
- Oracle to_date()函式的用法Oracle函式
- DOS命令之Date命令的用法
- linux 中 date命令的用法Linux
- date 物件物件
- JavaScript Date()JavaScript
- Java DateJava
- date命令
- javascript dateJavaScript
- JS DateJS
- js基礎–Date.parse()與Date.getTime()方法詳解JS
- Linux date命令詳解Linux
- java util date轉換成java sql dateJavaSQL
- Java 時間類 Date、Calendar 及用法Java
- 【轉】linux date的多個用法Linux
- Oracle的months_between(date1,date2)函式注意點Oracle函式
- Mysql date_format 與 Oracle to_char(date,’format’)MySqlORMOracle
- JavaScript Date valueOf()JavaScript
- JavaScript Date 物件JavaScript物件
- JavaScript Date() 方法JavaScript
- date型別型別
- Java Date SimpleDateFormatJavaORM
- Expression Date FunctionsExpressFunction
- JavaScript之DateJavaScript
- Oracle Date FunctionsOracleFunction
- Linux dateLinux
- linux date 命令詳解(ZT)Linux
- 什麼是Date物件一個內建物件Date:物件
- new Date(date).getTime()在蘋果手機不相容蘋果
- oracle timestamp轉換date及date型別相減Oracle型別
- JavaScript Date() 引數JavaScript