<EnableAmPmParseAdjustment > 元素<EnableAmPmParseAdjustment> Element

确定是否日期和时间分析方法使用调整后的规则集来分析日期字符串包含天、 月、 小时和 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><configuration>
<运行时 ><runtime>
<EnableAmPmParseAdjustment><EnableAmPmParseAdjustment>

语法Syntax

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

特性和元素Attributes and Elements

下列各节描述了特性、子元素和父元素。The following sections describe attributes, child elements, and parent elements.

特性Attributes

特性Attribute 描述Description
enabled 必需的特性。Required attribute.

指定是否日期和时间分析方法使用调整后的规则集来分析日期字符串包含仅日、 月、 小时和 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 特性enabled Attribute

Value DescriptionDescription
00 日期和时间分析方法不使用调整后的规则用于分析包含仅日、 月、 小时和 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 日期和时间分析方法的分析包含仅日、 月、 小时和 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.ParseExact,和DateTimeOffset.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.

下表说明了中的差异DateTime值时DateTime.Parse(String)方法用于分析字符串""4/10 6 AM"与<EnableAmPmParseAdjustment>元素的enabled属性设置为"0"或"1"。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 2017 年 1 月 5 日 4:00:00 AM1/5/2017 4:00:00 AM 2017 年 4 月 10 日上午 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