{"id":1890,"date":"2011-10-25T00:10:49","date_gmt":"2011-10-24T16:10:49","guid":{"rendered":"http:\/\/www.jpuyy.com\/blog\/?p=1890"},"modified":"2022-03-26T11:55:03","modified_gmt":"2022-03-26T03:55:03","slug":"linux-date-usage","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=1890","title":{"rendered":"linux\u4e0bdate\u547d\u4ee4\u5b9e\u4f8b"},"content":{"rendered":"<p>date\u547d\u4ee4\u5728linux\u5f88\u91cd\u8981\uff0c\u5c5e\u4e8e\u57fa\u7840\u547d\u4ee4\u4e4b\u4e00\uff0cdate\u547d\u4ee4\u7684\u529f\u80fd\u662f\u663e\u793a\u548c\u8bbe\u7f6e\u7cfb\u7edf\u65e5\u671f\u548c\u65f6\u95f4\u3002<\/p>\n<p>\u663e\u793a\u5f53\u524d\u65e5\u671f<\/p>\n<pre>#date<\/pre>\n<p>\u663e\u793a\u7ed3\u679c\u540e\u9762\u4f1a\u8ddf\u4e0a\u5982\u4e0b\u6807\u51c6\u65f6\u95f4\uff0c\u6ce8\u610f\u6362\u7b97<\/p>\n<p>CST\uff1a\u4e2d\u56fd\u6807\u51c6\u65f6\u95f4\uff08China Standard Time\uff09\uff0c\u4e3aGMT\u65f6\u95f4+8<\/p>\n<p>UTC\uff1a\u534f\u8c03\u4e16\u754c\u65f6\uff0c\u53c8\u79f0\u4e16\u754c\u6807\u51c6\u65f6\u95f4\uff0c\u7b80\u79f0UTC\uff0c\u4ece\u82f1\u6587\u56fd\u9645\u65f6\u95f4\/\u6cd5\u6587\u534f\u8c03\u65f6\u95f4\u201dUniversal Time\/Temps Cordonn\u00e9\u201d\u800c\u6765\u3002\u4e2d\u56fd\u5927\u9646\u3001\u9999\u6e2f\u3001\u6fb3\u95e8\u3001\u53f0\u6e7e\u3001\u8499\u53e4\u56fd\u3001\u65b0\u52a0\u5761\u3001\u9a6c\u6765\u897f\u4e9a\u3001\u83f2\u5f8b\u5bbe\u3001\u6fb3\u6d32\u897f\u90e8\u7684\u65f6\u95f4\u4e0eUTC\u7684\u65f6\u5dee\u5747\u4e3a+8\uff0c\u4e5f\u5c31\u662fUTC+8\u3002<\/p>\n<p>GMT\uff1a\u683c\u6797\u5c3c\u6cbb\u6807\u51c6\u65f6\u95f4\uff08\u65e7\u8bd1\u683c\u6797\u5a01\u6cbb\u5e73\u5747\u65f6\u95f4\u6216\u683c\u6797\u5a01\u6cbb\u6807\u51c6\u65f6\u95f4\uff1b\u82f1\u8bed\uff1aGreenwich Mean Time\uff0cGMT\uff09\u662f\u6307\u4f4d\u4e8e\u82f1\u56fd\u4f26\u6566\u90ca\u533a\u7684\u7687\u5bb6\u683c\u6797\u5c3c\u6cbb\u5929\u6587\u53f0\u7684\u6807\u51c6\u65f6\u95f4\uff0c\u56e0\u4e3a\u672c\u521d\u5b50\u5348\u7ebf\u88ab\u5b9a\u4e49\u5728\u901a\u8fc7\u90a3\u91cc\u7684\u7ecf\u7ebf\u3002<\/p>\n<p>date\u547d\u4ee4\u7684\u4e00\u822c\u683c\u5f0f\u4e3a\uff1a date [\u9009\u9879] \u663e\u793a\u65f6\u95f4\u683c\u5f0f\uff08\u4ee5+\u5f00\u5934\uff0c\u540e\u9762\u63a5\u683c\u5f0f\uff0c+\u4e0e%\u4e2d\u95f4\u6ca1\u6709\u7a7a\u683c\uff09<\/p>\n<p>date\u00a0\u9009\u9879\u53ca\u5176\u542b\u610f\uff1a<\/p>\n<p>-d datestring, &#8211;date datestring \u663e\u793a\u7531datestring\u63cf\u8ff0\u7684\u65e5\u671f<br \/>\n-s datestring, &#8211;set datestring \u8bbe\u7f6edatestr \u63cf\u8ff0\u7684\u65e5\u671f<br \/>\n-u, &#8211;universal \u663e\u793a\u6216\u8bbe\u7f6e\u901a\u7528\u65f6\u95f4\u65f6\u95f4\u57df<br \/>\n-R,\u00a0&#8211;rfc-2822 \u663e\u793a\u5f53\u524d\u65f6\u533a<\/p>\n<p>date \u65f6\u95f4\u683c\u5f0f\u53c2\u6570\uff08\u6ce8\u610f\u5927\u5c0f\u5199\uff09\uff1a<\/p>\n<p>%H \u5c0f\u65f6\uff0800..23\uff09<br \/>\n%I \u5c0f\u65f6\uff0801..12\uff09<br \/>\n%k \u5c0f\u65f6\uff080..23\uff09<br \/>\n%M \u5206\uff0800..59\uff09<br \/>\n%p \u663e\u793a\u51faAM\u6216PM<br \/>\n%r \u65f6\u95f4\uff08hh\uff1amm\uff1ass AM\u6216PM\uff09\uff0c12\u5c0f\u65f6<br \/>\n%s \u4ece1970\u5e741\u67081\u65e500\uff1a00\uff1a00\u5230\u76ee\u524d\u7ecf\u5386\u7684\u79d2\u6570\uff0c\u53ef\u4ee5\u7528\u6765\u7b97\u65f6\u95f4\u5dee<br \/>\n%S \u79d2\uff0800..59\uff09<br \/>\n%F YYYY-mm-dd\u683c\u5f0f\u7684\u5b8c\u6574\u65e5\u671f\uff08Full date\uff09\uff0c\u540c%Y-%m-%d<br \/>\n%T \u65f6\u95f4\uff0824\u5c0f\u65f6\u5236\uff09\uff08hh:mm:ss\uff09<br \/>\n%X \u663e\u793a\u65f6\u95f4\u7684\u683c\u5f0f\uff08%H:%M:%S\uff09<br \/>\n%Z \u65f6\u533a \u65e5\u671f\u57df<br \/>\n%a \u661f\u671f\u51e0\u7684\u7b80\u79f0\uff08 Sun..Sat\uff09<br \/>\n%A \u661f\u671f\u51e0\u7684\u5168\u79f0\uff08 Sunday..Saturday\uff09<br \/>\n%b \u6708\u7684\u7b80\u79f0\uff08Jan..Dec\uff09<br \/>\n%B \u6708\u7684\u5168\u79f0\uff08January..December\uff09<br \/>\n%c \u65e5\u671f \u661f\u671f\u548c\u65f6\u95f4\uff08 Mon Nov 8 14\uff1a12\uff1a46 CST 1999\uff09<br \/>\n%d \u4e00\u4e2a\u6708\u7684\u7b2c\u51e0\u5929\uff0801..31\uff09<br \/>\n%D \u65e5\u671f\uff08mm\/dd\/yy\uff09<br \/>\n%h \u548c%b\u9009\u9879\u76f8\u540c<br \/>\n%j \u4e00\u5e74\u7684\u7b2c\u51e0\u5929\uff08001..366\uff09<br \/>\n%m \u6708\uff0801..12\uff09<br \/>\n%w \u4e00\u4e2a\u661f\u671f\u7684\u7b2c\u51e0\u5929\uff080\u4ee3\u8868\u661f\u671f\u5929\uff09<br \/>\n%W \u4e00\u5e74\u7684\u7b2c\u51e0\u4e2a\u661f\u671f\uff0800..53\uff0c\u661f\u671f\u4e00\u4e3a\u7b2c\u4e00\u5929\uff09<br \/>\n%x \u663e\u793a\u65e5\u671f\u7684\u683c\u5f0f\uff08mm\/dd\/yy\uff09<br \/>\n%y \u5e74\u7684\u6700\u540e\u4e24\u4e2a\u6570\u5b57\uff08 1999\u5219\u662f99\uff09<br \/>\n%Y \u5e74\uff08\u4f8b\u5982\uff1a1970\uff0c1996\u7b49\uff09<\/p>\n<p>\u9700\u8981\u7279\u522b\u8bf4\u660e\u7684\u662f\uff0c\u53ea\u6709\u8d85\u7ea7\u7528\u6237\u624d\u80fd\u7528date\u547d\u4ee4\u8bbe\u7f6e\u65f6\u95f4\uff0c\u4e00\u822c\u7528\u6237\u53ea\u80fd\u7528date\u547d\u4ee4\u663e\u793a\u65f6\u95f4\u3002<\/p>\n<p>\u663e\u793a\u6211\u4eec\u4e2d\u56fd\u4eba\u6bd4\u8f83\u559c\u6b22\u7684\u683c\u5f0f<\/p>\n<pre>date +%Y\/%m\/%d\" \u00a0\"%H:%M:%S\r\n2012\/11\/14 \u00a008:42:48<\/pre>\n<p>\u4e0b\u5217\u73af\u5883\u53d8\u91cf\u5c06\u4f1a\u5f71\u54cd\u5230 date \u547d\u4ee4\u7684\u6267\u884c\u6548\u679c\u3002<br \/>\nLANG \u786e\u5b9a\u5728 LC_ALL \u548c\u76f8\u5e94\u7684\u73af\u5883\u53d8\u91cf\uff08\u4ee5 LC_ \u5f00\u5934\uff09\u90fd\u4e0d\u6307\u5b9a\u8bed\u8a00\u73af\u5883\u7684\u65f6\u5019\u5c06\u8981\u4f7f\u7528\u7684\u7f3a\u7701\u8bed\u8a00\u73af\u5883\u3002<br \/>\nLC_ALL \u786e\u5b9a\u7528\u4e8e\u8986\u76d6\u7531 LANG \u6216\u4efb\u4f55\u4ee5 LC_ \u5f00\u5934\u7684\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u7684\u4efb\u4f55\u8bed\u8a00\u73af\u5883\u7c7b\u522b\u503c\u7684\u8bed\u8a00\u73af\u5883\u3002<br \/>\nLC_CTYPE \u786e\u5b9a\u6587\u672c\u6570\u636e\u7684\u5b57\u8282\u5e8f\u5217\u89e3\u91ca\u4e3a\u5b57\u7b26\u65f6\u4f7f\u7528\u7684\u8bed\u8a00\u73af\u5883\uff08\u4f8b\u5982\u53c2\u6570\u4e2d\u5355\u5bf9\u591a\u5b57\u8282\u5b57\u7b26\uff09\u3002<br \/>\nLC_MESSAGES \u51b3\u5b9a\u5199\u4fe1\u606f\u5e94\u4f7f\u7528\u7684\u8bed\u8a00\u3002<br \/>\nLC_TIME \u786e\u5b9a\u7531 date \u5199\u5165\u7684\u65e5\u671f\u548c\u65f6\u95f4\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\u3002<br \/>\nNLSPATH \u4e3a\u5904\u7406 LC_MESSAGES \u51b3\u5b9a\u6d88\u606f\u76ee\u5f55\u7684\u4f4d\u7f6e\u3002<br \/>\nTZ \u6307\u5b9a\u65f6\u95f4\u548c\u65e5\u671f\u4f7f\u7528\u7684\u65f6\u533a\uff0c\u9664\u975e\u6307\u5b9a\u4e86 -u \u9009\u9879\u3002\u5982\u679c\u672a\u8bbe\u7f6e TZ \u53d8\u91cf\u4e14\u672a\u6307\u5b9a -u \u6807\u5fd7\uff0c\u5219\u4f7f\u7528\u975e\u6307\u5b9a\u7684\u7cfb\u7edf\u7f3a\u7701\u65f6\u533a\u3002<\/p>\n<p>\u4f7f\u7528\u793a\u4f8b\u2014\u2014\u8bbe\u7f6e\u7bc7:<\/p>\n<p>\u8bbe\u7f6e\u5f53\u524d\u65f6\u95f4\uff0c\u53ea\u6709root\u6743\u9650\u624d\u80fd\u8bbe\u7f6e\uff0c\u5176\u4ed6\u53ea\u80fd\u67e5\u770b\u3002<\/p>\n<p>\u8bbe\u7f6e\u621020061010\uff0c\u8fd9\u6837\u4f1a\u628a\u53ea\u6709\u65e5\u671f\u7684\u8bdd\uff0c\u65f6\u523b\u4f1a\u4e3a00:00:00<\/p>\n<pre>#date -s 20061010<\/pre>\n<p>\u8bbe\u7f6e\u5177\u4f53\u65f6\u523b\uff0c\u4e0d\u5bf9\u65e5\u671f\u505a\u66f4\u6539<\/p>\n<pre>#date -s 12:23:23<\/pre>\n<p>\u8bbe\u7f6e\u5168\u90e8\u65e5\u671f\u548c\u65f6\u523b<\/p>\n<pre>#date -s \"12:12:23 2006-10-10\"<\/pre>\n<p>\u5c06\u65f6\u95f4\u4e0einternet\u540c\u6b65\u5e76\u5199\u5165bios\u8bf7\u67e5\u770b\uff1ahttp:\/\/jpuyy.com\/2011\/10\/change-time-zone-and-use-ntpdate.html<\/p>\n<p>\u4f7f\u7528\u793a\u4f8b\u2014\u2014\u663e\u793a\u7bc7:<\/p>\n<p>\u7528\u6307\u5b9a\u7684\u683c\u5f0f\u663e\u793a\u65f6\u95f4\u3002\u5728man date\u7684-d\u9009\u9879\u4e2d\uff0c\u8bf4\u660e\u4e86\u663e\u793a\u7684\u662f\u540e\u9762\u63cf\u8ff0\u7684\u65f6\u95f4\uff0c\u5e76\u4e0d\u4e00\u5b9a\u662f\u5f53\u524d\u65f6\u95f4\u3002<\/p>\n<p>-d, &#8211;date=STRING<br \/>\ndisplay time described by STRING, not `now&#8217;<\/p>\n<p>\u4e0b\u9762\u51e0\u4e2a\u5b9e\u4f8b\u7075\u6d3b\u7684\u8fd0\u7528\u4e86\u53c2\u6570\uff0c\u663e\u793a\u51fa\u60f3\u8981\u7684\u65f6\u95f4\u6548\u679c\u3002<br \/>\n\u663e\u793a\u660e\u5929<\/p>\n<pre>#\u00a0date -d next-day +%Y%m%d\r\n \u6216\uff1a# date -d tomorrow +%Y%m%d<\/pre>\n<p>\u663e\u793a\u6628\u5929<\/p>\n<pre> # date -d last-day +%Y%m%d\r\n \u6216\uff1a# date -d yesterday +%Y%m%d\r\n \u6216\uff1a# date -d \"1 days ago\" +%Y%m%d<\/pre>\n<p>\u663e\u793a\u4e0a\u4e2a\u6708\uff1a<\/p>\n<pre> # date -d last-month +%Y%m<\/pre>\n<p>\u663e\u793a\u4e0b\u4e2a\u6708\uff1a<\/p>\n<pre> # date -d next-month +%Y%m<\/pre>\n<p>\u663e\u793a\u660e\u5e74\uff1a<\/p>\n<pre> # date -d next-year +%Y<\/pre>\n<p>\u53ef\u4ee5\u770b\u51fa\u8981\u663e\u793a\u67d0\u5929\/\u5468\/\u6708\/\u5e74\u4e4b\u524d\u6216\u4e4b\u540e\uff0c\u53ef\u76f4\u63a5\u7528\u7c7b\u4f3c\u4e8e\u4e0b\u9762\u7684\u547d\u4ee4\uff1bx\u7528\u6570\u5b57\u4ee3\u66ff\uff0c\u5982\u679c\u9700\u8981\u51e0\u5e74\u524d\u7684\u76f4\u63a5\u5199\u6b63\u6570\uff0c\u5982\u679c\u8981\u51e0\u5e74\u540e\u7684\u65e5\u671f\u76f4\u63a5\u5199\u8d1f\u6570\u5373\u53ef\uff1b<\/p>\n<pre>date -d \"x days ago\" +%Y%m%d\r\ndate -d \"x weeks ago\" +%Y%m%d\r\ndate -d \"x months ago\" +%Y%m%d\r\ndate -d \"x years ago\" +%Y%m%d<\/pre>\n<p>\u62ff\u5230 timestamp \u8f6c\u5316\u6210 datetime<\/p>\n<pre>date -d @1457431246<\/pre>\n<p>datetime \u8f6c\u6362\u4e3a timestamp<\/p>\n<pre>date -d '2017-08-16' \"+%s\"<\/pre>\n<p><strong>\u5e38\u7528<\/strong><\/p>\n<pre>date +%F_%H-%M-%S\r\n2021-09-13_22-58-56\r\ndate +%F_%T\r\n2022-03-26_11:53:20\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>date\u547d\u4ee4\u5728linux\u5f88\u91cd\u8981\uff0c\u5c5e\u4e8e\u57fa\u7840\u547d\u4ee4\u4e4b\u4e00\uff0cdate\u547d\u4ee4\u7684\u529f\u80fd\u662f\u663e\u793a\u548c\u8bbe\u7f6e\u7cfb\u7edf\u65e5\u671f\u548c\u65f6\u95f4\u3002 \u663e\u793a\u5f53\u524d\u65e5\u671f #date \u663e\u793a\u7ed3\u679c\u540e\u9762\u4f1a\u8ddf\u4e0a\u5982\u4e0b\u6807\u51c6\u65f6\u95f4\uff0c\u6ce8\u610f\u6362\u7b97 CST\uff1a\u4e2d\u56fd\u6807\u51c6\u65f6\u95f4\uff08China Standard Time\uff09\uff0c\u4e3aGMT\u65f6\u95f4+8 UTC\uff1a\u534f\u8c03\u4e16\u754c\u65f6\uff0c\u53c8\u79f0\u4e16\u754c\u6807\u51c6\u65f6\u95f4\uff0c\u7b80\u79f0UTC\uff0c\u4ece\u82f1\u6587\u56fd\u9645\u65f6\u95f4\/\u6cd5\u6587\u534f\u8c03\u65f6\u95f4\u201dUniversal Time\/Temps Cordonn\u00e9\u201d\u800c\u6765\u3002\u4e2d\u56fd\u5927\u9646\u3001\u9999\u6e2f\u3001\u6fb3\u95e8\u3001\u53f0\u6e7e\u3001\u8499\u53e4\u56fd\u3001\u65b0\u52a0\u5761\u3001\u9a6c\u6765\u897f\u4e9a\u3001\u83f2\u5f8b\u5bbe\u3001\u6fb3\u6d32\u897f\u90e8\u7684\u65f6\u95f4\u4e0eUTC\u7684\u65f6\u5dee\u5747\u4e3a+8\uff0c\u4e5f\u5c31\u662fUTC+8\u3002 GMT\uff1a\u683c\u6797\u5c3c\u6cbb\u6807\u51c6\u65f6\u95f4\uff08\u65e7\u8bd1\u683c\u6797\u5a01\u6cbb\u5e73\u5747\u65f6\u95f4\u6216\u683c\u6797\u5a01\u6cbb\u6807\u51c6\u65f6\u95f4\uff1b\u82f1\u8bed\uff1aGreenwich Mean Time\uff0cGMT\uff09\u662f\u6307\u4f4d\u4e8e\u82f1\u56fd\u4f26\u6566\u90ca\u533a\u7684\u7687\u5bb6\u683c\u6797\u5c3c\u6cbb\u5929\u6587\u53f0\u7684\u6807\u51c6\u65f6\u95f4\uff0c\u56e0\u4e3a\u672c\u521d\u5b50\u5348\u7ebf\u88ab\u5b9a\u4e49\u5728\u901a\u8fc7\u90a3\u91cc\u7684\u7ecf\u7ebf\u3002 date\u547d\u4ee4\u7684\u4e00\u822c\u683c\u5f0f\u4e3a\uff1a date [\u9009\u9879] \u663e\u793a\u65f6\u95f4\u683c\u5f0f\uff08\u4ee5+\u5f00\u5934\uff0c\u540e\u9762\u63a5\u683c\u5f0f\uff0c+\u4e0e%\u4e2d\u95f4\u6ca1\u6709\u7a7a\u683c\uff09 date\u00a0\u9009\u9879\u53ca\u5176\u542b\u610f\uff1a -d datestring, &#8211;date datestring \u663e\u793a\u7531datestring\u63cf\u8ff0\u7684\u65e5\u671f -s datestring, &#8211;set datestring \u8bbe\u7f6edatestr \u63cf\u8ff0\u7684\u65e5\u671f -u, &#8211;universal \u663e\u793a\u6216\u8bbe\u7f6e\u901a\u7528\u65f6\u95f4\u65f6\u95f4\u57df -R,\u00a0&#8211;rfc-2822 \u663e\u793a\u5f53\u524d\u65f6\u533a date \u65f6\u95f4\u683c\u5f0f\u53c2\u6570\uff08\u6ce8\u610f\u5927\u5c0f\u5199\uff09\uff1a %H \u5c0f\u65f6\uff0800..23\uff09 %I \u5c0f\u65f6\uff0801..12\uff09 %k \u5c0f\u65f6\uff080..23\uff09 %M \u5206\uff0800..59\uff09 %p \u663e\u793a\u51faAM\u6216PM %r \u65f6\u95f4\uff08hh\uff1amm\uff1ass AM\u6216PM\uff09\uff0c12\u5c0f\u65f6 %s \u4ece1970\u5e741\u67081\u65e500\uff1a00\uff1a00\u5230\u76ee\u524d\u7ecf\u5386\u7684\u79d2\u6570\uff0c\u53ef\u4ee5\u7528\u6765\u7b97\u65f6\u95f4\u5dee %S \u79d2\uff0800..59\uff09 %F YYYY-mm-dd\u683c\u5f0f\u7684\u5b8c\u6574\u65e5\u671f\uff08Full [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[23],"class_list":["post-1890","post","type-post","status-publish","format-standard","hentry","category-linux","tag-summary"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/1890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1890"}],"version-history":[{"count":16,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/1890\/revisions"}],"predecessor-version":[{"id":9534,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/1890\/revisions\/9534"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}