{"id":4871,"date":"2018-04-14T11:24:08","date_gmt":"2018-04-14T03:24:08","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=4871"},"modified":"2018-04-15T09:33:00","modified_gmt":"2018-04-15T01:33:00","slug":"%e6%95%99%e7%a8%8bdatetimefromstring-%e5%87%bd%e6%95%b0%e7%9a%84%e4%bd%bf%e7%94%a8%e8%af%b4%e6%98%8e","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=4871","title":{"rendered":"[\u6559\u7a0b]DateTimeFromString \u51fd\u6570\u7684\u4f7f\u7528\u8bf4\u660e"},"content":{"rendered":"<p>DateTimeFromString \u7528\u4e8e\u5c06\u4e00\u4e2a\u65e5\u671f\u65f6\u95f4\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\u8868\u8fbe\u5f0f\u8f6c\u6362\u4e3a\u65e5\u671f\u65f6\u95f4\u7c7b\u578b\uff0c\u7528\u4e8e\u66ff\u4ee3 Delphi \u81ea\u5df1\u7684 StrToDate \u51fd\u6570\uff08\u5f31\u5f31\u7684\u4e00\u4e2a\u51fd\u6570\uff0c\u6211\u4e00\u76f4\u5ffd\u7565\u5b83\u7684\u5b58\u5728\uff09\u3002<\/p>\n<p>\u5728\u7edd\u5927\u90e8\u5206\u573a\u666f\u4e0b\uff0cDateTimeFromString \u53ef\u4ee5\u6b63\u786e\u8bc6\u522b\u591a\u54b1\u683c\u5f0f\u7684\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32\uff0c\u4f46\u5e76\u4e0d\u4ee3\u8868\u5b83\u7684\u81ea\u52a8\u8bc6\u522b\u667a\u80fd\u5230\u53ef\u4ee5\u7406\u89e3\u4e00\u5207\uff0c<strong>\u5bf9\u4e8e m\/d\/y \u6216 d\/m\/y \u8fd9\u79cd\u683c\u5f0f\uff0c\u5f53 m \u548c d \u7684\u503c\u572812\u53ca\u4ee5\u4e0b\u65f6\uff0c\u5b83\u65e0\u6cd5\u8bc6\u522b\u5e94\u8be5\u5339\u914d\u90a3\u79cd\u683c\u5f0f\uff0c\u6240\u4ee5\u9ed8\u8ba4\u5339\u914d\u7684\u662f \u00a0d\/m\/y\uff0c\u5982\u679c\u4e0d\u6b63\u786e\uff0c\u5c31\u9700\u8981\u4f60\u4eba\u5de5\u6307\u5b9a\u683c\u5f0f\u53c2\u6570\u3002<\/strong><\/p>\n<p>DateTimeFromString \u4f7f\u7528\u7684\u65e5\u671f\u65f6\u95f4\u7c7b\u578b\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u540c FormatDateTime \u51fd\u6570\uff0c\u76f8\u5173\u8bf4\u660e\u8bf7\u53c2\u8003 FormatDateTime \u7684\u8bf4\u660e\u3002<\/p>\n<p>\u5982\u679c\u4e0d\u4f20\u683c\u5f0f\u5b57\u7b26\u4e32\uff0c\u5219\u4e3a\u81ea\u52a8\u8bc6\u522b\u6a21\u5f0f\uff0c\u652f\u6301\u8bc6\u522b\u4ee5\u4e0b\u683c\u5f0f\uff1a<\/p>\n<ul>\n<li>\u7eaf\u6570\u5b57\uff1ayymmdd yymmddhhnnss yymmddhhnnsszzz yyyymmdd yyyymmddhhnnss yyyymmddhhnnsszzz hhnnss hhnnsszzz<\/li>\n<li>\u5176\u5b83\u683c\u5f0f\uff1ay-m-d h:n:s.z\u3001y-m-d h:n:s\u3001y-m-d\u3001h:n:s.z\u3001h:n:s\u3001y-m-d&#8221;T&#8221;h:n:s.z\u3001y-m-d&#8221;T&#8221;h:n:s\u3001d\/m\/y h:n:s.z\u3001d\/m\/y h:n:s\u3001d\/m\/y\u3001m\/d\/y h:n:s.z\u3001m\/d\/y h:n:s\u3001m\/d\/y\u3001y\/m\/d h:n:s.z\u3001y\/m\/d h:n:s\u3001y\/m\/d \u7b49\u7b49\u51e0\u4e4e\u5404\u79cd\u5e38\u89c1\u7684\u5df2\u77e5\u683c\u5f0f<\/li>\n<li>Unix\/Web \u65f6\u95f4\u6233\u683c\u5f0f\uff0c\u5982\uff1a13-Apr-2018 14:29:59 GMT+08:00\uff0c\u6ce8\u610f\u8fd9\u79cd\u5e26\u65f6\u533a\u7684\u683c\u5f0f\u4f1a\u4e00\u5f8b\u8f6c\u6362\u4e3a\u5bf9\u5e94\u7684 UTC \u65f6\u95f4\uff0c\u6240\u4ee5\u8981\u8f6c\u6362\u4e3a\u672c\u5730\u65f6\u95f4\uff0c\u8bf7\u81ea\u884c\u52a0\u4e0a\u65f6\u533a<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u662f\u5b9e\u9645\u7684\u7528\u4f8b\u6d4b\u8bd5\u7ed3\u679c\uff1a<\/p>\n<blockquote><p>2017-3-5T6:12:34.879<br \/>\nyyyy-m-d&#8221;T&#8221;h:n:s.z =&gt; 2017-03-05 06:12:34.879<\/p>\n<p>2017-3-5T6:12:34.879<br \/>\n\u81ea\u52a8\u8bc6\u522b =&gt; 2017-03-05 06:12:34.879<\/p>\n<p>20170305061234879<br \/>\n\u81ea\u52a8\u8bc6\u522b =&gt; 2017-03-05 06:12:34.879<\/p>\n<p>20170305<br \/>\n\u81ea\u52a8\u8bc6\u522b =&gt; 2017-03-05 00:00:00.000<\/p>\n<p>061234879<br \/>\n\u81ea\u52a8\u8bc6\u522b =&gt; 1899-12-30 06:12:34.879<\/p>\n<p>20170305061234<br \/>\n\u81ea\u52a8\u8bc6\u522b =&gt; 2017-03-05 06:12:34.000<\/p>\n<p>2017-3-5 6:12:34.879<br \/>\n\u81ea\u52a8\u8bc6\u522b =&gt; 2017-03-05 06:12:34.879<\/p>\n<p>17-3-5 6:12:34.879<br \/>\n\u81ea\u52a8\u8bc6\u522b =&gt; 2017-03-05 06:12:34.879<\/p>\n<p>17-3-5<br \/>\n\u81ea\u52a8\u8bc6\u522b =&gt; 2017-03-05 00:00:00.000<\/p>\n<p>31\/5\/2018<br \/>\n\u81ea\u52a8\u8bc6\u522b =&gt; 2018-05-31 00:00:00.000<\/p>\n<p>5\/31\/2018<br \/>\n\u81ea\u52a8\u8bc6\u522b =&gt; 2018-05-31 00:00:00.000<\/p>\n<p>2018\/01\/02 11:22:25.111<br \/>\n\u81ea\u52a8\u8bc6\u522b =&gt; 2018-01-02 11:22:25.111<\/p>\n<p>2018\u5e741\u67082\u65e5 11\u70b922\u520625\u79d2<br \/>\ny\u5e74m\u6708d\u65e5 h\u70b9n\u5206s\u79d2 =&gt; 2018-01-02 11:22:25.000<\/p>\n<p>Fri, 13 Apr 2018 14:29:59 GMT<br \/>\n\u81ea\u52a8\u8bc6\u522b =&gt; 2018-04-13 14:29:59.000<\/p>\n<p>13-Apr-2018 14:29:59 GMT+08:00<br \/>\n\u81ea\u52a8\u8bc6\u522b =&gt; 2018-03-11 06:29:59.000<\/p><\/blockquote>\n<p>\u4e0b\u9762\u7684\u81ea\u52a8\u8bc6\u522b\u53ef\u80fd\u4e0d\u6b63\u786e\uff0c\u9700\u8981\u624b\u52a8\u6307\u5b9a\u683c\u5f0f<\/p>\n<blockquote><p>12\/10\/1998<br \/>\n\u81ea\u52a8\u8bc6\u522b =&gt; 1998-10-12 00:00:00.000<\/p>\n<p>12\/10\/1998<br \/>\nm\/d\/y =&gt; 1998-12-10 00:00:00.000<\/p>\n<p>12\/10\/1998<br \/>\nd\/m\/y =&gt; 1998-10-12 00:00:00.000<\/p><\/blockquote>\n<p>\u8fd9\u4e2a\u51fd\u6570\u6709\u4e24\u4e2a\u91cd\u8f7d\uff0c\u53c2\u6570\u4e0d\u7528\u8bf4\u660e\u4e00\u770b\u5c31\u77e5\u9053\u600e\u4e48\u7528\u3002\u5982\u679c\u4f60\u4e0d\u77e5\u9053\uff0c\u90a3\u6211\u4e5f\u4e0d\u77e5\u9053\uff0c\u51fd\u6570\u58f0\u660e\u5982\u4e0b\uff1a<\/p>\n<pre class=\"lang:delphi decode:true \">function DateTimeFromString(AStr: String; var AResult: TDateTime;\r\n  AFormat: String): Boolean; overload;\r\nfunction DateTimeFromString(Str: String; AFormat: String; ADef: TDateTime = 0)\r\n  : TDateTime; overload;<\/pre>\n<p>\u597d\u5427\uff0c\u8fd9\u4e24\u4e2a\u91cd\u8f7d\u770b\u8d77\u6765\u51e0\u4e4e\u4e00\u6837\uff0c\u8c03\u7528\u7684\u4f8b\u5b50\uff1a<\/p>\n<pre class=\"lang:delphi decode:true \">if DateTimeFromString('2017-3-5T6:12:34.879',ATime,'') then\r\n  ...\r\n\r\nATime:=DateTimeFromString('2017-3-5T6:12:34.879','',Now);<\/pre>\n<p>\u5982\u679c\u4f60\u5728\u5b9e\u9645\u4f7f\u7528\u4e2d\u9047\u5230\u95ee\u9898\uff0c\u6b22\u8fce\u5230\u5b98\u65b9QQ\u7fa4\u53cd\u9988\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>DateTimeFromString \u7528 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[69,8,603],"tags":[],"class_list":["post-4871","post","type-post","status-publish","format-standard","hentry","category-c-builder","category-delphi","category-603"],"views":3982,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4871","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4871"}],"version-history":[{"count":2,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4871\/revisions"}],"predecessor-version":[{"id":4877,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4871\/revisions\/4877"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}