{"id":76,"date":"2010-08-05T09:30:47","date_gmt":"2010-08-05T01:30:47","guid":{"rendered":"http:\/\/ipcpu.sa.cy.com\/?p=76"},"modified":"2010-08-05T09:30:47","modified_gmt":"2010-08-05T01:30:47","slug":"linux-study-date","status":"publish","type":"post","link":"https:\/\/c.ipcpu.com\/2010\/08\/linux-study-date\/","title":{"rendered":"Linux\u5b66\u4e60\u7b14\u8bb0\u4e4bdate\u547d\u4ee4"},"content":{"rendered":"

\u4e00\u3001\u81ea\u5b9a\u4e49\u8f93\u51fa<\/strong><\/p>\n

[root@cent1 ~]# date +%Y-%m-%d
\n2010-07-17
\n[root@cent1 ~]#
\n[root@cent1 ~]# date +\u2019%Y-%m-%d %H:%M:%S\u2019
\n2010-07-17 22:55:32
\n[root@cent1 ~]#
\n[root@cent1 ~]# date +\u2019%H:%M:%S\u2019
\n22:55:44
\n[root@cent1 ~]#
\n[root@cent1 sbin]# date +%T
\n00:08:20
\n[root@cent1 sbin]#<\/span><\/p>\n

\u4e8c\u3001date -d \u7684\u4f7f\u7528<\/strong><\/p>\n

[root@cent1 ~]# date
\nSat Jul 17 22:50:59 EDT 2010
\n[root@cent1 ~]#
\n[root@cent1 ~]# date -d \u201910 days\u2019
\nTue Jul 27 22:51:05 EDT 2010
\n[root@cent1 ~]#
\n[root@cent1 ~]# date -d \u2018-10 days\u2019
\nWed Jul? 7 22:51:10 EDT 2010
\n[root@cent1 ~]#
\n[root@cent1 ~]# date -d yesterday
\nFri Jul 16 22:51:22 EDT 2010
\n[root@cent1 ~]#
\n[root@cent1 ~]#
\n[root@cent1 ~]# date -d 20100607
\nMon Jun? 7 00:00:00 EDT 2010
\n[root@cent1 ~]#
\n[root@cent1 ~]# date -d 0607
\nSat Jul 17 06:07:00 EDT 2010
\n[root@cent1 ~]#
\n[root@cent1 ~]# date -d 060712
\nWed Jul 12 00:00:00 EDT 2006
\n[root@cent1 ~]#<\/span><\/p>\n

\u4e09\u3001\u811a\u672c\u5e94\u7528<\/span><\/strong><\/p>\n

[root@cent1 2010-07-17]# cat ..\/date.sh
\n#!\/bin\/bash
\ndir=\/root\/
\nmkdir $dir$(date +%Y-%m-%d)
\ncd $dir$(date +%Y-%m-%d)
\ntouch xixi.test<\/p>\n

\u56db\u3001clock\u548chwclock<\/strong><\/p>\n

[root@cent1 sbin]# ll | grep clock
\nlrwxrwxrwx 1 root root?????????? 7 Jul 13 01:02 clock -> hwclock
\n-rwxr-xr-x 1 root root?????? 31820 Sep? 3? 2009 hwclock
\n[root@cent1 ~]# whereis clock
\nclock: \/sbin\/clock \/usr\/share\/man\/man3p\/clock.3p.gz \/usr\/share\/man\/man3\/clock.3.gz
\n[root@cent1 ~]# whereis hwclock
\nhwclock: \/sbin\/hwclock \/usr\/sbin\/hwclock \/usr\/share\/man\/man8\/hwclock.8.gz<\/p>\n

hwclock\u548cclock\u8fd8\u662f\u6709\u4e00\u4e9b\u5dee\u522b\u7684\uff0c\u5dee\u522b\u5728\u54ea\u6211\u4e5f\u4e0d\u6e05\u695a
\n[root@cent1 sbin]# date
\nSat Jul 17 23:24:59 EDT 2010
\n[root@cent1 sbin]# clock
\nSat 17 Jul 2010 11:25:02 PM EDT? -0.781589 seconds
\n[root@cent1 sbin]#<\/p>\n

clock\u662f\u4f7f\u7528PM AM\u65b9\u5f0f\u8868\u793a\u7684\uff0c12\u5c0f\u65f6\u5236\uff0cdate\u4e3a24\u5c0f\u65f6\u5236\u3002<\/strong><\/span><\/p>\n

\u4e94\u3001\u65f6\u95f4\u540c\u6b65\u3001\u65f6\u95f4\u8c03\u6574<\/strong><\/p>\n

(1)date 042612492005? #2005-04-26 12:49
\n(2)hwclock -w? #\u5199\u5165\u673a\u5668<\/span><\/p>\n

\u5176\u4ed6\u7684\u65b9\u6cd5<\/p>\n

[root@cent1 sbin]# date 07172323
\nSat Jul 17 23:23:00 EDT 2010<\/span>
\n#\u8bbe\u7f6e\u4e86\u6708\u4efd\u548c\u65f6\u95f4<\/p>\n

[root@cent1 sbin]# date +%T -s 23:20:00
\n23:20:00
\n[root@cent1 sbin]# date
\nTue Apr 26 23:20:03 EDT 2005
\n[root@cent1 sbin]#<\/span>
\n#\u4ec5\u8bbe\u7f6e\u65f6\u95f4<\/p>\n

[root@cent1 sbin]# date +%Y%m%d -s 20100717
\n20100717
\n[root@cent1 sbin]# date
\nSat Jul 17 00:00:06 EDT 2010<\/span>
\n# \u4ec5\u8bbe\u7f6e\u65e5\u671f\uff0c!\u6b64\u79cd\u65b9\u6cd5\u4f1a\u5c06\u65f6\u95f4\u4ece\u96f6\u70b9\u5f00\u59cb\u8ba1\u65f6<\/p>\n

?================<\/p>\n

[root@cent1 ~]# date
\nSat Jul 17 22:22:13 EDT 2010? #\u665a\u4e0a 22:22
\n[root@cent1 ~]# clock
\nSat 17 Jul 2010 11:27:38 PM EDT? -0.800734 seconds #\u665a\u4e0a23:27
\n[root@cent1 ~]#
\n[root@cent1 ~]# clock -w??? #\u7cfb\u7edf\u65f6\u95f4\u5199\u5165\u786c\u4ef6
\n[root@cent1 ~]#
\n[root@cent1 ~]# clock?????? #\u7cfb\u7edf\u65f6\u95f4\u53d8\u4e3a\u665a\u4e0a22:22
\nSat 17 Jul 2010 10:22:41 PM EDT? -0.723272 seconds
\n[root@cent1 ~]#<\/p>\n

clock\u8868\u793a\u7684\u662fBIOS\u65f6\u95f4\uff0cdate\u662f\u7cfb\u7edf\u65f6\u95f4\u3002<\/strong><\/span><\/p>\n

hwclock -w or hwclock \u2013systohc
\nhwclock -s or hwclock \u2013hctosys
\n\u53c2\u6570\u4f5c\u7528
\n\u2013hctosys
\n??? Set the System Time from the Hardware Clock.[Hardware->sys]
\n\u2013systohc
\n??? Set the Hardware Clock to the current System Time.[sys->hard]
\n\u516d\u3001NTP<\/strong><\/p>\n

centos\u9ed8\u8ba4\u6ca1\u88c5
\nyum install ntp
\n[root@cent1 ~]# ntpdate 210.72.145.44<\/p>\n

#crontab -e
\n\u52a0\u5165\u4e00\u884c\uff1a 15 3 * * * \/usr\/sbin\/ntpdate 210.72.145.44> \/dev\/null 2>&1<\/p>\n

\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1aIPCPU-\u7f51\u7edc\u4e4b\u8def<\/a> » Linux\u5b66\u4e60\u7b14\u8bb0\u4e4bdate\u547d\u4ee4<\/a><\/p>","protected":false},"excerpt":{"rendered":"

\u4e00\u3001\u81ea\u5b9a\u4e49\u8f93\u51fa [root@cent1 ~]# date +%Y-%m-%d 2010-07-17 [root@cent1 ~]# [root@cent1 ~]# date +\u2019%Y-%m-%d %H:%M:%S\u2019 2010-07-17 22:55:32 [root@cent1 ~]# [root@cent1 ~]# date +\u2019%H:%M:%S\u2019 22:55:44 [root@cent1 ~]# [root@cent1 sbin]# date +%T 00:08:20 [root@cent1 sbin]# \u4e8c\u3001date -d \u7684\u4f7f\u7528 [root@cent1 ~]# date Sat Jul 17 22:50:59 EDT 2010 [root@cent1 ~]# [root@cent1 ~]# date -d \u201910 days\u2019 Tue Jul 27 22:51:05 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[],"_links":{"self":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/76"}],"collection":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/comments?post=76"}],"version-history":[{"count":0,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/76\/revisions"}],"wp:attachment":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/media?parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/categories?post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/tags?post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}