<EnableAmPmParseAdjustment> 項目<EnableAmPmParseAdjustment> Element

判斷日期和時間剖析方法是否使用一組已調整的規則,來剖析包含 day、month、hour 和 AM/PM 指示項的日期字串。Determines whether date and time parsing methods use an adjusted set of rules to parse date strings that contain a day, month, hour, and AM/PM designator.

<configuration>
  <runtime>
    <EnableAmPmParseAdjustment>

SyntaxSyntax

<EnableAmPmParseAdjustment enabled="0"|"1" />  

屬性和項目Attributes and Elements

下列章節說明屬性、子元素和父元素。The following sections describe attributes, child elements, and parent elements.

屬性Attributes

屬性Attribute 描述Description
enabled 必要屬性。Required attribute.

指定日期和時間剖析方法是否使用一組已調整的規則,來剖析只包含 day、month、hour 和 AM/PM 指示項的日期字串。Specifies whether date and time parsing methods use an adjusted set of rules to parse date strings that contain only a day, month, hour, and AM/PM designator.

啟用屬性enabled Attribute

Value 描述Description
00 日期和時間剖析方法不會使用已調整的規則,來剖析只包含 day、month、hour 和 AM/PM 指示項的日期字串。Date and time parsing methods do not use adjusted rules for parsing date strings that contain only a day, month, hour, and AM/PM designator.
11 日期和時間剖析方法使用已調整的規則,來剖析只包含 day、month、hour 和 AM/PM 指示項的日期字串。Date and time parsing methods use adjusted rules for parsing date strings that contain only a day, month, hour, and AM/PM designator.

子元素Child Elements

無。None.

父項目Parent Elements

項目Element 描述Description
configuration 通用語言執行平台和 .NET Framework 應用程式所使用之每個組態檔中的根項目。The root element in every configuration file used by the common language runtime and .NET Framework applications.
runtime 包含有關執行階段初始化選項的資訊。Contains information about runtime initialization options.

備註Remarks

專案 <EnableAmPmParseAdjustment> 會控制下列方法如何剖析包含數位日和月的日期字串,後面接著一小時和 AM/PM 指示項 (例如 "4/10 6 AM" ) :The <EnableAmPmParseAdjustment> element controls how the following methods parse a date string that contains a numeric day and month followed by an hour and an AM/PM designator (such as "4/10 6 AM"):

其他模式都不會受到影響。No other patterns are affected.

<EnableAmPmParseAdjustment>元素對於 DateTime.ParseExactDateTime.TryParseExactDateTimeOffset.ParseExactDateTimeOffset.TryParseExact 方法沒有任何作用。The <EnableAmPmParseAdjustment> element has no effect on the DateTime.ParseExact, DateTime.TryParseExact, DateTimeOffset.ParseExact, and DateTimeOffset.TryParseExact methods.

重要

在 .NET Core 和 .NET Native 中,依預設會啟用已調整的 AM/PM 剖析規則。In .NET Core and .NET Native, the adjusted AM/PM parsing rules are enabled by default.

如果未啟用剖析調整規則,則會將字串的第一個數位解釋為12小時制的小時,並忽略 AM/PM 指示項以外的字串其餘部分。If the parsing adjustment rule is not enabled, the first digit of the string is interpreted as the hour of the 12-hour clock, and the remainder of the string except for the AM/PM designator is ignored. 剖析方法所傳回的日期和時間,包含從日期字串中解壓縮之當日的目前日期和小時。The date and time returned by the parsing method consists of the current date and the hour of the day extracted from the date string.

如果已啟用剖析調整規則,則剖析方法會將日期和月份解讀為屬於目前年份,並將時間轉譯為12小時制的小時。If the parsing adjustment rule is enabled, parsing method interpret the day and month as belonging to the current year, and interpret the time as the hour of the 12-hour clock.

下表說明 DateTimeDateTime.Parse(String) 方法用來剖析 <EnableAmPmParseAdjustment> 元素的 enabled 屬性設定為 "0" 或 "1" 的字串 "" 4/10 6 AM "時,值中的差異。The following table illustrates the difference in the DateTime value when the DateTime.Parse(String) method is used to parse the string ""4/10 6 AM" with the <EnableAmPmParseAdjustment> element's enabled property set to "0" or "1". 它會假設今天的日期為2017年1月5日,並將日期顯示為使用指定文化特性的 "G" 格式字串來格式化。It assumes that today's date is January 5, 2017, and displays the date as if it is formatted using the specified culture's "G" format string.

文化特性名稱Culture name enabled = "0"enabled="0" enabled = "1"enabled="1"
en-USen-US 上午 1/5/2017 4:00:001/5/2017 4:00:00 AM 上午 4/10/2017 6:00:004/10/2017 6:00:00 AM
en-GBen-GB 5/1/2017 6:00:005/1/2017 6:00:00 10/4/2017 6:00:0010/4/2017 6:00:00

另請參閱See also