{"id":10189,"date":"2024-09-15T00:47:17","date_gmt":"2024-09-14T16:47:17","guid":{"rendered":"https:\/\/bohu.net\/blog\/?p=10189"},"modified":"2024-09-15T00:47:17","modified_gmt":"2024-09-14T16:47:17","slug":"linux%e4%b8%8bdate%e7%9a%84%e9%bb%98%e8%ae%a4%e8%be%93%e5%87%ba%e6%a0%bc%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/as32.net\/blog\/10189\/","title":{"rendered":"Linux\u4e0bdate\u7684\u9ed8\u8ba4\u8f93\u51fa\u683c\u5f0f"},"content":{"rendered":"\n<p>\u5728\u4e24\u4e2adebian\u4e3b\u673a\u4e0b \u4f7f\u7528date\u547d\u4ee4\uff0c\u663e\u793a\u7684\u683c\u5f0f\u4e0d\u4e00\u6837\uff0c\u5206\u4e3a\u4e24\u79cd\uff08A\/B\uff09\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A\uff1aSat Sep 14 10:15:03 PM CST 2024<\/li>\n\n\n\n<li>B\uff1aSat Sep 14 22:15:15 CST 2024<\/li>\n<\/ul>\n\n\n\n<p>\u4ee5\u665a\u4e0a\u5341\u70b9\u4e00\u523b\u4e3a\u4f8b\uff0cA \u768410:15\u662f12\u5c0f\u65f6\u5236\uff0c\u5e26\u6709PM\uff0c B\u768422:15\u662f24\u5c0f\u65f6\u5236\uff0c\u6ca1\u6709PM\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u95ee\u9898\u662f, \u5982\u4f55\u8bbe\u7f6e12\u5c0f\u65f6\u5236 \u4e3a 24\u5c0f\u65f6\u5236?  \u7ee7\u7eed\u5c1d\u8bd5\u51e0\u79cd\u6d89\u53ca\u65f6\u95f4\u8bbe\u7f6e\u7684\u547d\u4ee4\u3002<\/p>\n\n\n\n<p>\u4f7f\u7528 timedatectl\u67e5\u770b \uff1a \uff08<em>\u9898\u5916\u8bdd:\u8be5\u547d\u4ee4\u5728wsl\uff0cwindows\u5b50\u7cfb\u7edf\u4e2d\u65e0\u6548<\/em>\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>timedatectl status<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"> timedatectl status<br>               Local time: Sat 2024-09-14 21:56:01 CST<br>           Universal time: Sat 2024-09-14 13:56:01 UTC<br>                 RTC time: Sat 2024-09-14 13:55:53<br>                Time zone: Asia\/Shanghai (CST, +0800)<br>System clock synchronized: no<br>              NTP service: n\/a<br>          RTC in local TZ: no<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">timedatectl status<br>               Local time: Sat 2024-09-14 21:56:07 CST<br>           Universal time: Sat 2024-09-14 13:56:07 UTC<br>                 RTC time: n\/a<br>                Time zone: Asia\/Shanghai (CST, +0800)<br>System clock synchronized: no<br>              NTP service: n\/a<br>          RTC in local TZ: no<\/pre>\n\n\n\n<p>&#8220;Local time&#8221; , &#8220;Universal time&#8221;, &#8220;Time zone&#8221;  \u65f6\u95f4\u90fd\u662f\u6b63\u786e\uff0c\u5e76\u4e00\u81f4\u7684\u3002\u65f6\u949f\u540c\u6b65\uff0cNTP\u670d\u52a1\u4e5f\u90fd\u5e76\u672a\u4f7f\u7528\u3002RTC time\u4e00\u4e2a\u6709\u65f6\u95f4\uff0c\u4e00\u4e2a\u4e3a\u7a7a\uff0c\u5e94\u8be5\u662f\u865a\u62df\u5316\u4e0d\u540c\u7684\u95ee\u9898\u3002\u770b\u6765timedatectl\u7684\u4fe1\u606f\u5e76\u4e0d\u663e\u793a\u65f6\u95f4\u662f\u542612\/24\u5236\u5f0f\u3002<\/p>\n\n\n\n<p>locale \u67e5\u770b\u672c\u5730\u8bbe\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>locale -a<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">C<br>C.utf8<br>en_US.utf8<br>POSIX<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">C<br>C.utf8<br>POSIX<br>en_US.utf8<\/pre>\n\n\n\n<p>\u90fd\u662f &#8220;en_US.utf8&#8243;\uff0c\u53ea\u662f POSIX\u987a\u5e8f\u4e0d\u7528\uff0c\u4e5f\u65e0\u5173\u3002<\/p>\n\n\n\n<p>\u4f7f\u7528 dpkg-reconfigure tzdata \u91cd\u65b0\u8bbe\u7f6e\u65f6\u533a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dpkg-reconfigure tzdata<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"691\" class=\"wp-image-10190\" style=\"width: 600px;\" src=\"https:\/\/bohu.net\/blog\/wp-content\/uploads\/2024\/09\/2024-09-14.png\" alt=\"\" srcset=\"https:\/\/as32.net\/blog\/wp-content\/uploads\/2024\/09\/2024-09-14.png 883w, https:\/\/as32.net\/blog\/wp-content\/uploads\/2024\/09\/2024-09-14-260x300.png 260w, https:\/\/as32.net\/blog\/wp-content\/uploads\/2024\/09\/2024-09-14-768x885.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/pre>\n\n\n\n<p>\u4e4b\u540e\u518d\u770bdate\uff0c\u7ed3\u679c\u8bc1\u660e\u4e5f\u4e0e\u65f6\u95f412\/24\u5236\u5f0f\u65e0\u5173\u3002<\/p>\n\n\n\n<p>\u4f7f\u7528 <strong>date  &#8211;debug<\/strong>\uff0c\u4f1a\u663e\u793a\u8f93\u51fa\u683c\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>date --debug<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">date --debug<br>date: output format: \u2018%a %b %e %r %Z %Y\u2019<br>Sat Sep 14 10:15:03 PM CST 2024<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">date --debug<br>date: output format: '%a %b %e %H:%M:%S %Z %Y'<br>Sat Sep 14 22:14:50 CST 2024<\/pre>\n\n\n\n<p>\u770b\u5230\u4e0d\u540c\u4e86\u628a\uff1f date \u8f93\u51fa\u4e0d\u540c\u65f6\u95f4\u8fdb\u5236\uff0c\u4e0e\u8bbe\u7f6e\u65f6\u95f4\u7684\u547d\u4ee4\u65e0\u5173\u3002\u53ea\u6709\u8f93\u51fa\u4e2a\u683c\u5f0f\u7684\u4e0d\u540c\u3002\u90a3\u4e48\u8fd9\u4e2a\u683c\u5f0f\u662f\u4ec0\u4e48\u51b3\u5b9a\u7684\uff1f\u5728\u54ea\u91cc\u5b9a\u4e49\u7684\uff1f<\/p>\n\n\n\n<p><strong>\u4e4b\u540e\u770b\u5230\u8fd9\u7bc7\u6587\u7ae0\uff1a<\/strong><a href=\"https:\/\/linuxopsys.com\/change-default-date-format-in-linux\">https:\/\/linuxopsys.com\/change-default-date-format-in-linux<\/a><\/p>\n\n\n\n<p>\u539f\u6765 date \u547d\u4ee4\u7684<strong>\u9ed8\u8ba4\u65e5\u671f\u683c\u5f0f<\/strong>\u3002\u662f\u6839\u636e\u00a0<strong>locale \u4e2d\u7684 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-red-color\">LC_TIME<\/mark> \u53c2\u6570<\/strong>\uff0c\u6839\u636e\u53c2\u6570\u540d\uff0c\u4f7f\u7528\u5173\u8054\u7684\u8bbe\u7f6e\u6587\u4ef6\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff0c\u8fd0\u884c <strong>locale <\/strong>\u547d\u4ee4\u5e76\u67e5\u627e <strong>LC_TIME<\/strong> \u53d8\u91cf\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/linuxopsys.com\/wp-content\/uploads\/2023\/11\/change-date-format-091123-01.png\" alt=\"locale\" class=\"wp-image-7368\"\/><\/figure>\n\n\n\n<p>\u5982\u56fe\uff0c\u770b\u5230 LC_TIME = \u201cen_US.UTF-8\u201c\uff0c\u8fd9\u662f\u7f8e\u56fd\u5e38\u7528\u7684\u65e5\u671f\u683c\u5f0f\u3002<\/p>\n\n\n\n<p>\u7b2c 2 \u6b65\uff1a\u627e\u5230\u4e0e Locale \u5173\u8054\u7684\u6587\u4ef6<br>locale \u6587\u4ef6\u901a\u5e38\u4f4d\u4e8e \/usr\/share\/i18n\/locales\/ \u4e2d\u3002\u60a8\u5c06\u627e\u5230\u4e00\u4e2a\u540d\u79f0\u4e0e\u60a8\u7684 LC_TIME locale \u8bbe\u7f6e\u76f8\u5bf9\u5e94\u7684\u6587\u4ef6\uff0c\u5982\u679c  LC_TIME \u533a\u57df\u8bbe\u7f6e\u662f en_US, \u5bf9\u5e94\u6587\u4ef6\u4e3a\/<strong>usr\/share\/i18n\/locales\/en_US<\/strong><\/p>\n\n\n\n<p><br>\u67e5\u770b Locale \u6587\u4ef6\uff0c\u53ef\u4ee5\u770b\u5230\u5176\u4e2d\u7684 <strong>date_fmt<\/strong>  \u4e4b\u540e\u7684\u5b9a\u4e49 \u4e0e date &#8211;debug \u663e\u793a\u7684\u8f93\u51fa\u683c\u5f0f\u4e00\u6837\uff0c<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/12\u5c0f\u65f6<br>\"%a %b %e %r %Z %Y\"<br><br>\/\/24\u5c0f\u65f6<br>\"%a %b %e %H:%M:%S %Z %Y\"<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>~ # date +\"%a %b %e %r %Z %Y\"\nSun Sep 15 12:16:14 AM CST 2024\n\n~ # date +\"%a %b %e %H:%M:%S %Z %Y\"\nSun Sep 15 00:17:31 CST 2024<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528 date + &#8220;\u8f93\u51fa\u683c\u5f0f&#8221; \u6d4b\u8bd5\uff0c \u7531\u6b64\u6211\u4eec\u53d1\u73b0\u4e86\u95ee\u9898\u6839\u6e90\u3002\u4f46\u662f\u4ec0\u4e48\uff0c\u4e24\u4e2a\u201c<strong>LC_TIME<\/strong> \u201d \u90fd\u662f \u201c<strong>en_US<\/strong>\u201d\uff0c\u683c\u5f0f\u4f1a\u4e0d\u540c\u5462\uff1f\u7b54\u6848\u5728 en_US \u6587\u4ef6\u7684\u6ce8\u91ca\u4e2d\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>% Appropriate date and time representation for date(1). This is<br>% different from d_t_fmt for historical reasons and has been different<br>% since 2000 when date_fmt was added as a GNU extension. At the end<br>% of <strong>2018<\/strong> it was adjusted to use 12H time (bug 24046) instead of 24H.<\/p>\n<\/blockquote>\n\n\n\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0c\u4e00\u4e2a\u7cfb\u7edf\u662f2018\u5e74\u524d\u5b89\u88c5\uff0c\u6216\u8bbe\u7f6e\u751f\u6210\u7684 Locale \u6587\u4ef6\uff0c\u4e00\u4e2a\u662f\u57282018\u5e74\u4e4b\u540e<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">\u7ed3\u5c3e<\/mark><\/h2>\n\n\n\n<p>\u5982\u6b64\uff0c\u660e\u767d\u4e86\u95ee\u9898\u6839\u6e90\uff0c\u5c31\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539 <strong>locale <\/strong>\u6587\u4ef6\u7684<strong>date_fmt<\/strong>   \u6216 \u91cd\u65b0\u8bbe\u7f6e <strong>LC_TIME<\/strong> \u73af\u5883\u53d8\u91cf\uff0c\u91cd\u65b0\u751f\u6210\u533a\u57df\u8bbe\u7f6e\u6587\u4ef6\u4ee5\u5e94\u7528\u66f4\u6539\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>locale-gen\nupdate-locale<\/code><\/pre>\n\n\n\n<p>\u6216\u8005 \u7528\u66f4\u7b80\u5355\u7684\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export LC_TIME=POSIX<\/code><\/pre>\n\n\n\n<p>\u76f4\u63a5\u8bbe\u7f6e <strong>LC_TIME=POSIX<\/strong>\uff0c\u53ef\u4ee5\u5feb\u901f\u7edf\u4e00\u591a\u53f0\uff0c\u4e0d\u540c\u672c\u5730\u8bed\u8a00\u8bbe\u7f6e\u7684\u65f6\u95f4\u683c\u5f0f\u3002<\/p>\n\n\n\n<p>\u3010END\u3011<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4e24\u4e2adebian\u4e3b\u673a\u4e0b \u4f7f\u7528date\u547d\u4ee4\uff0c\u663e\u793a\u7684\u683c\u5f0f\u4e0d\u4e00\u6837\uff0c\u5206\u4e3a\u4e24\u79cd\uff08A\/B\uff09\uff1a \u4ee5\u665a\u4e0a\u5341\u70b9\u4e00\u523b\u4e3a\u4f8b\uff0cA \u7684 &hellip; <a href=\"https:\/\/as32.net\/blog\/10189\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cLinux\u4e0bdate\u7684\u9ed8\u8ba4\u8f93\u51fa\u683c\u5f0f\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[746,6,10,26,27,29],"tags":[796,798,799,791,793,792,794,789,797,795,800],"class_list":["post-10189","post","type-post","status-publish","format-standard","hentry","category-bash","category-linux","category-vps","category-26","category-27","category-29","tag-usr-share-i18n-locales","tag-a-b-e-hms-z-y","tag-a-b-e-r-z-y","tag-12h","tag-793","tag-24h","tag-794","tag-date","tag-en_us","tag-lc_time","tag-lc_timeposix"],"_links":{"self":[{"href":"https:\/\/as32.net\/blog\/wp-json\/wp\/v2\/posts\/10189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/as32.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/as32.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/as32.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/as32.net\/blog\/wp-json\/wp\/v2\/comments?post=10189"}],"version-history":[{"count":1,"href":"https:\/\/as32.net\/blog\/wp-json\/wp\/v2\/posts\/10189\/revisions"}],"predecessor-version":[{"id":10191,"href":"https:\/\/as32.net\/blog\/wp-json\/wp\/v2\/posts\/10189\/revisions\/10191"}],"wp:attachment":[{"href":"https:\/\/as32.net\/blog\/wp-json\/wp\/v2\/media?parent=10189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/as32.net\/blog\/wp-json\/wp\/v2\/categories?post=10189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/as32.net\/blog\/wp-json\/wp\/v2\/tags?post=10189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}