<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>

语法Syntax

<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 特性enabled Attribute

Value 说明Description
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.TryParseExactThe <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) 使用方法分析字符串 "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"
zh-CNen-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