Uredi

Deli z drugimi prek


<EnableAmPmParseAdjustment> Element

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.

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
0 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.
1 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 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

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.

The <EnableAmPmParseAdjustment> element has no effect on the DateTime.ParseExact, DateTime.TryParseExact, DateTimeOffset.ParseExact, and DateTimeOffset.TryParseExact methods.

Important

In .NET Core and .NET Native, the adjusted AM/PM parsing rules are enabled by default.

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.

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.

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". 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="1"
en-US 1/5/2017 4:00:00 AM 4/10/2017 6:00:00 AM
en-GB 5/1/2017 6:00:00 10/4/2017 6:00:00

See also