From ceccaaada0c3f012cb296785d325579d55b13bcf Mon Sep 17 00:00:00 2001 From: Ron Petrusha Date: Tue, 13 Feb 2018 08:16:48 -0800 Subject: [PATCH 1/9] Revision of DateTime.Parse --- xml/System/DateTime.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xml/System/DateTime.xml b/xml/System/DateTime.xml index 9a2af32955eba..23734f24c2770 100644 --- a/xml/System/DateTime.xml +++ b/xml/System/DateTime.xml @@ -4466,7 +4466,7 @@ An object that is equivalent to the date and time contained in `s`. A string that contains a date and time to convert. - Converts the string representation of a date and time to its equivalent. + Converts the string representation of a date and time to its equivalent by using the conventions of the current thread culture. An object that is equivalent to the date and time contained in . A string that contains a date and time to convert. An object that supplies culture-specific formatting information about s. A bitwise combination of the enumeration values that indicates the style elements that can be present in s for the parse operation to succeed, and that defines how to interpret the parsed date in relation to the current time zone or the current date. A typical value to specify is . - Converts the string representation of a date and time to its equivalent by using culture-specific format information and formatting style. + Converts the string representation of a date and time to its equivalent by using culture-specific format information and a formatting style. An object that is equivalent to the date and time contained in , as specified by and . Date: Tue, 13 Feb 2018 14:51:22 -0800 Subject: [PATCH 2/9] Additional modifications --- xml/System/DateTime.xml | 73 +++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/xml/System/DateTime.xml b/xml/System/DateTime.xml index 23734f24c2770..1b9168e34161b 100644 --- a/xml/System/DateTime.xml +++ b/xml/System/DateTime.xml @@ -4236,33 +4236,18 @@ juillet 2009 ## Remarks In this section: - [Overloaded method syntax](#Syntax) - [Parameters](#Params) - [Return value](#Returns) - [Exceptions](#Exceptions) [Which method do I call?](#Tasks) [The string to parse](#StringToParse) [Parsing and cultural conventions](#Culture) [Parsing and style elements](#Styles) + [The return value and DateTime.Kind](#kind) Examples: [DateTime.Parse(String)](#Parse1_Example) [DateTime.Parse(String, IFormatProvider)](#Parse2_Example) [DateTime.Parse(String, IFormatProvider, DateTimeStyles)](#Parse3_Example) [Version information](#Versions) - - -## Overloaded method syntax - For additional guidance on choosing an overload, see [Which method do I call?](#Tasks) - - `DateTime.Parse(String s)` - For the conversion, uses the formatting conventions of the current thread culture and interprets the string based on the style flag ([example](#Parse1_Example)). - - `DateTime.Parse(String s, IFormatProvider provider)` - For the conversion, uses the formatting conventions of a specified culture and interprets the string based on the style flag ([example](#Parse2_Example)). - - `DateTime.Parse(String s, IFormatProvider provider, DateTypeStyles styles)` - For the conversion, uses the formatting conventions of a specified culture and interprets the string based on specified style flags ([example](#Parse3_Example)). + + ## Which method do I call? @@ -4313,6 +4299,7 @@ An object that is equivalent to the date and time contained in `s`. |Parse a date and time string by using the conventions of the current culture.| overload| |Parse a date and time string by using the conventions of a specific culture.| overload (see [Parsing and Cultural Conventions](#Culture))| |Parse a date and time string with special style elements (such as white space or no white space).| overload| +|Parse a date and time string that must be in a particular format.| or | |Parse a date and time string and perform a conversion to UTC or local time.| overload| |Parse a date and time string without handling exceptions.| method| |Restore (round-trip) a date and time value created by a formatting operation.|Pass the "o" or "r" standard format string to the method, and call the overload with | @@ -4323,7 +4310,7 @@ An object that is equivalent to the date and time contained in `s`. The method tries to convert the string representation of a date and time value to its equivalent. It tries to parse `s` completely without throwing a exception. > [!IMPORTANT] -> Because the string representation of a date and time must conform to a recognized pattern, you should always use exception handling when calling the method to parse user input. If you don't want to handle exceptions, you can call the method to parse the date and time string; this method returns a value that indicates whether the parse operation succeeded. +> Because the string representation of a date and time must conform to a recognized pattern, you should always use exception handling when calling the method to parse user input. If you don't want to handle exceptions, you can call the method to parse the date and time string; this method returns a value that indicates whether the parse operation succeeded. The string to be parsed can take any of the following forms: @@ -4335,7 +4322,7 @@ An object that is equivalent to the date and time contained in `s`. - A string that includes time zone information and conforms to ISO 8601. In the following examples, the first string designates Coordinated Universal Time (UTC), and the second string designates the time in a time zone that's seven hours earlier than UTC: - 2008-11-01T19:35:00.0000000Z + 2008-11-01T19:35:00.0000000Z 2008-11-01T19:35:00.0000000-07:00 - A string that includes the GMT designator and conforms to the RFC 1123 time format; for example: @@ -4346,20 +4333,20 @@ An object that is equivalent to the date and time contained in `s`. 03/01/2009 05:42:00 -5:00 - If `s` is the string representation of a leap day in a leap year in the calendar used by the parsing method (see [Parsing and cultural conventions](#Culture)), the method parses `s` successfully. If `s` is the string representation of a leap day in a non-leap year, the method throws a exception. + If `s` is the string representation of a leap day in a leap year in the calendar used by the parsing method (see [Parsing and cultural conventions](#Culture)), the method parses `s` successfully. If `s` is the string representation of a leap day in a non-leap year, the method throws a . - Because the method tries to parse the string representation of a date and time by using the formatting rules of the current or specified culture, trying to parse a string across different cultures can fail. To parse a specific date and time format across different locales, use one of the overloads of the method and provide a format specifier. + Because the method tries to parse the string representation of a date and time by using the formatting rules of the current or a specified culture, trying to parse a string across different cultures can fail. To parse a specific date and time format across different locales, use one of the overloads of the method and provide a format specifier. ## Parsing and cultural conventions - All overloads of the method are culture-sensitive unless the string to be parsed conforms to the ISO 8601 pattern. The parsing operation usesthe formatting information in a object that is derived as follows: + All overloads of the method are culture-sensitive unless the string to be parsed conforms to the ISO 8601 pattern. The parsing operation uses the formatting information in a object that is derived as follows: |If you call|And `provider` is|Formatting information is derived from| |-----------------|-----------------------|--------------------------------------------| ||-|The current thread culture ( property)| -| or | object|The specified object| +| or |a object|The specified object| | or |`null`|The current thread culture ( property)| -| or | object|The property| +| or |a object|The property| | or |Custom implementation|The method| When formatting information is derived from a object, the property defines the calendar used in the parsing operation. @@ -4394,7 +4381,43 @@ An object that is equivalent to the date and time contained in `s`. ||Specifies that if `s` lacks any time zone information, UTC is assumed. Unless the flag is present, the method converts the returned value from UTC to local time and sets its property to .| ||Although valid, this value is ignored.| ||For strings that contain time zone information, tries to prevent the conversion of a date and time string to a value that represents a local time with its property set to . Typically, such a string is created by calling the method and by using the "o", "r", or "u" standard format specifier.| + + +## The return value and DateTime.Kind + +The `DateTime.Parse` overloads return a value whose property includes time zone information. It can indicate that the time is: + +- Coordinated Universal Time (). +- The time in the local time zone (). +- The time in an unknown time zone (xref:System.DateTimeKind.Unspecified?displayProperty=fullName>). + + Generally, the method returns a object whose property is . However, the method may also perform time zone conversion and set the value of the property differently, depending on the values of the `s` and `styles` parameters: + +|If|Time zone conversion|Kind property| +|--------|--------------------------|-------------------| +|`s` contains time zone information.|The date and time is converted to the time in the local time zone.|| +|`s` contains time zone information, and `styles` includes the flag.|The date and time is converted to Coordinated Universal Time (UTC).|| +|`s` contains the Z or GMT time zone designator, and `styles` includes the flag.|The date and time are interpreted as UTC.|| + The following example converts date strings that contain time zone information to the time in the local time zone: + + [!code-csharp[System.DateTime.Parse#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse2.cs#2)] + [!code-vb[System.DateTime.Parse#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse2.vb#2)] + + You can also preserve the value of a date and time's property during a formatting and parsing operation by using the flag. The following example illustrates how the flag affects the parsing operation on values that are converted to strings by using the "o", "r", or "u" format specifier. + + [!code-csharp[System.DateTime.Parse#5](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse5.cs#5)] + [!code-vb[System.DateTime.Parse#5](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse5.vb#5)] + +## Examples + +Numerous examples that call the `DateTime.Parse` method are interspersed throughout the [Remarks](#remarks) section of this article and in the documentation for the individual `DateTime.Parse` overloads. + +> [!NOTE] +> The C# examples in this article run in the [Try.NET](https://try.dot.net) inline code runner and playground. You can run an example in an interactive window by pressing the **Run** button. Once you execute the code, you can modify it and run the modified code by pressing **Run** again. The modified code either runs in the interactive window or, if compilation fails, the interactive window displays all C# compiler error messages. + +You can also download a complete set of `DateTime.Parse` examples, which are included in a [.NET Core 2.0 project for C#]() and a [.NET Core 2.0 project for Visual Basic](), from the [dotnet/docs GitHub repository](https://github.com/dotnet/docs). + ## DateTime.Parse(String) example The following example parses the string representation of several date and time values by using default provider and style values: the formatting conventions of the en-US culture, which is the current thread culture of the computer used to produce the example output, and the style flag. It handles the exception that is thrown when the method tries to parse the string representation of a date and time by using some other culture's formatting conventions. It also shows how to successfully parse a date and time value that does not use the formatting conventions of the current thread culture. From 70438cc4e821b504a2d86057d4e5831275e2f54c Mon Sep 17 00:00:00 2001 From: Ron Petrusha Date: Tue, 20 Feb 2018 16:15:25 -0800 Subject: [PATCH 3/9] Some further revisions --- xml/System/DateTime.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xml/System/DateTime.xml b/xml/System/DateTime.xml index 1b9168e34161b..d41e9fb7ef3a9 100644 --- a/xml/System/DateTime.xml +++ b/xml/System/DateTime.xml @@ -4318,7 +4318,11 @@ An object that is equivalent to the date and time contained in `s`. - A string with a date but no time component. If the time component is absent, the method assumes 12:00 midnight. If the date component has a two-digit year, it is converted to a year based on the of the current culture's current calendar or the specified culture's current calendar (if you use an overload with a non-null `provider` argument). -- A string with a time but no date component. The method assumes the current date unless you call the overload and include in the `styles` parameter, in which case the method assumes January 1, 0001. +- A string with a date component that includes only the month and the year but no day component. The method assumes the first day of the month. + +- A string with a date component that includes only the month and the day but no year component. The method assumes the current year. + +- A string with a time but no date component. The method assumes the current date unless you call the overload and include in the `styles` argument, in which case the method assumes January 1, 0001. - A string that includes time zone information and conforms to ISO 8601. In the following examples, the first string designates Coordinated Universal Time (UTC), and the second string designates the time in a time zone that's seven hours earlier than UTC: From 497b7d73b1ffc0284a6e5bba034e7a3b09c480a9 Mon Sep 17 00:00:00 2001 From: Ron Petrusha Date: Wed, 21 Feb 2018 16:41:04 -0800 Subject: [PATCH 4/9] Additional revisions --- xml/System/DateTime.xml | 125 +++++++++++++--------------------------- 1 file changed, 39 insertions(+), 86 deletions(-) diff --git a/xml/System/DateTime.xml b/xml/System/DateTime.xml index d41e9fb7ef3a9..d2c5caa5ea0f2 100644 --- a/xml/System/DateTime.xml +++ b/xml/System/DateTime.xml @@ -4245,54 +4245,9 @@ juillet 2009 [DateTime.Parse(String)](#Parse1_Example) [DateTime.Parse(String, IFormatProvider)](#Parse2_Example) [DateTime.Parse(String, IFormatProvider, DateTimeStyles)](#Parse3_Example) -[Version information](#Versions) - - -## Which method do I call? +### Which method do I call? |To|Call| |--------|----------| @@ -4306,7 +4261,7 @@ An object that is equivalent to the date and time contained in `s`. |Parse a date and time string in a fixed format across machine (and possibly cultural) boundaries.| or method| -## The string to parse +### The string to parse The method tries to convert the string representation of a date and time value to its equivalent. It tries to parse `s` completely without throwing a exception. > [!IMPORTANT] @@ -4342,7 +4297,7 @@ An object that is equivalent to the date and time contained in `s`. Because the method tries to parse the string representation of a date and time by using the formatting rules of the current or a specified culture, trying to parse a string across different cultures can fail. To parse a specific date and time format across different locales, use one of the overloads of the method and provide a format specifier. -## Parsing and cultural conventions +### Parsing and cultural conventions All overloads of the method are culture-sensitive unless the string to be parsed conforms to the ISO 8601 pattern. The parsing operation uses the formatting information in a object that is derived as follows: |If you call|And `provider` is|Formatting information is derived from| @@ -4369,7 +4324,7 @@ An object that is equivalent to the date and time contained in `s`. > For more information see the "Dynamic culture data" section in the topic and the "Persisting DateTime values" section in the topic. -## Parsing and style elements +### Parsing and style elements All overloads ignore leading, inner, or trailing white-space characters in `s`. The date and time can be bracketed with a pair of leading and trailing NUMBER SIGN characters ("#", U+0023), and can be trailed with one or more NULL characters (U+0000). In addition, the overload has a `styles` parameter that consists of one or more members of the enumeration. This parameter defines how `s` should be interpreted and how the parse operation should convert `s` to a date and time. The following table describes the effect of each member on the parse operation. @@ -4387,7 +4342,7 @@ An object that is equivalent to the date and time contained in `s`. ||For strings that contain time zone information, tries to prevent the conversion of a date and time string to a value that represents a local time with its property set to . Typically, such a string is created by calling the method and by using the "o", "r", or "u" standard format specifier.| -## The return value and DateTime.Kind +### The return value and DateTime.Kind The `DateTime.Parse` overloads return a value whose property includes time zone information. It can indicate that the time is: @@ -4405,15 +4360,17 @@ The `DateTime.Parse` overloads return a value whose property during a formatting and parsing operation by using the flag. The following example illustrates how the flag affects the parsing operation on values that are converted to strings by using the "o", "r", or "u" format specifier. + You can also preserve the value of a date and time's property during a formatting and parsing operation by using the flag. The following example illustrates how the flag affects the parsing operation on values that are converted to strings by using the "o", "r", or "u" format specifier. - [!code-csharp[System.DateTime.Parse#5](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse5.cs#5)] + [!code-csharp-interactive[System.DateTime.Parse#5](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse5.cs#5)] [!code-vb[System.DateTime.Parse#5](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse5.vb#5)] -## Examples +### Examples Numerous examples that call the `DateTime.Parse` method are interspersed throughout the [Remarks](#remarks) section of this article and in the documentation for the individual `DateTime.Parse` overloads. @@ -4426,37 +4383,23 @@ You can also download a complete set of `DateTime.Parse` examples, which are inc ## DateTime.Parse(String) example The following example parses the string representation of several date and time values by using default provider and style values: the formatting conventions of the en-US culture, which is the current thread culture of the computer used to produce the example output, and the style flag. It handles the exception that is thrown when the method tries to parse the string representation of a date and time by using some other culture's formatting conventions. It also shows how to successfully parse a date and time value that does not use the formatting conventions of the current thread culture. - [!code-csharp[System.DateTime.Parse#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse1.cs#1)] + [!code-csharp-interactive[System.DateTime.Parse#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse1.cs#1)] [!code-vb[System.DateTime.Parse#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse1.vb#1)] ## DateTime.Parse(String, IFormatProvider) example The following example parses an array of date strings by using the conventions of the en-US, fr-FR, and de-DE cultures. It demonstrates that the string representations of a single date can be interpreted differently across different cultures. - [!code-csharp[System.DateTime.Parse#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse3.cs#3)] + [!code-csharp-interactive[System.DateTime.Parse#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse3.cs#3)] [!code-vb[System.DateTime.Parse#3](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse3.vb#3)] ## DateTime.Parse(String, IFormatProvider, DateTimeStyles) example The following example demonstrates the method and displays the value of the property of the resulting values. - [!code-csharp[System.DateTime.Parse#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse4.cs#4)] + [!code-csharp-interactive[System.DateTime.Parse#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse4.cs#4)] [!code-vb[System.DateTime.Parse#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse4.vb#4)] - -## Version information - .NET Framework - All overloads are supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0 - - .NET Framework Client Profile - All overloads are supported in: 4, 3.5 SP1 - - Portable Class Library - All overloads are supported - - .NET for Windows Store apps - All overloads are supported in: Windows 8 - ]]> @@ -4492,7 +4435,7 @@ You can also download a complete set of `DateTime.Parse` examples, which are inc - A string that contains a date and time to convert. + A string that contains a date and time to convert. See [The string to parse](#StringToParse) for more information. Converts the string representation of a date and time to its equivalent by using the conventions of the current thread culture. An object that is equivalent to the date and time contained in . @@ -4500,9 +4443,12 @@ You can also download a complete set of `DateTime.Parse` examples, which are inc ## Remarks -> [!NOTE] -> For examples and comprehensive usage information about this and other overloads of the `Parse` method, see the overload summary. - +If `s` contains time zone information, this method returns a value whose property is and converts the date and time in `s` to local time. Otherwise, it performs no time zone conversion and returns a value whose property is . + +This overload attempts to parse `s` by using the formatting conventions of the current culture. The current culture is indicated by the property. To parse a string using the formatting conventions of a specific culture, call the or the overloads. + +This overload attempts to parse `s` by using style. + ]]> @@ -4544,8 +4490,8 @@ You can also download a complete set of `DateTime.Parse` examples, which are inc - A string that contains a date and time to convert. - An object that supplies culture-specific format information about s. + A string that contains a date and time to convert. See [The string to parse](#StringToParse) for more information. + An object that supplies culture-specific format information about s. See [Parsing and cultural conventions](#Culture) Converts the string representation of a date and time to its equivalent by using culture-specific format information. An object that is equivalent to the date and time contained in as specified by . @@ -4553,9 +4499,10 @@ You can also download a complete set of `DateTime.Parse` examples, which are inc ## Remarks -> [!NOTE] -> For examples and comprehensive usage information about this and other overloads of the `Parse` method, see the overload summary. - +If `s` contains time zone information, this method returns a value whose property is and converts the date and time in `s` to local time. Otherwise, it performs no time zone conversion and returns a value whose property is . + +This overload attempts to parse `s` by using style. + ]]> @@ -4598,8 +4545,8 @@ You can also download a complete set of `DateTime.Parse` examples, which are inc - A string that contains a date and time to convert. - An object that supplies culture-specific formatting information about s. + A string that contains a date and time to convert. See [The string to parse](#StringToParse) for more information. + An object that supplies culture-specific formatting information about s. See [Parsing and cultural conventions](#Culture) A bitwise combination of the enumeration values that indicates the style elements that can be present in s for the parse operation to succeed, and that defines how to interpret the parsed date in relation to the current time zone or the current date. A typical value to specify is . Converts the string representation of a date and time to its equivalent by using culture-specific format information and a formatting style. An object that is equivalent to the date and time contained in , as specified by and . @@ -4607,10 +4554,16 @@ You can also download a complete set of `DateTime.Parse` examples, which are inc [!NOTE] -> For examples and comprehensive usage information about this and other overloads of the `Parse` method, see the overload summary. - + +This method overload converts the date and time in `s` and sets the property of the returned value as follows: + +|If |Time zone conversion|Kind property| +|---------------------------|--------------------------| +|`s` contains no time zone information.|None.|| +|`s` contains time zone information.|To the time in the local time zone|| +|`s` contains time zone information, and `styles includes the flag.|To Coordinated Univeral Time (UTC)|| +|`s` contains the Z or GMT time zone designator, and `styles` includes the .|None.|| + ]]> From 28e10fde66b2c9803090bedd021bc999612a5b5b Mon Sep 17 00:00:00 2001 From: Ron Petrusha Date: Thu, 22 Feb 2018 08:47:18 -0800 Subject: [PATCH 5/9] Corrected bad XML tags --- xml/System/DateTime.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xml/System/DateTime.xml b/xml/System/DateTime.xml index d2c5caa5ea0f2..a5365f6e8a2f3 100644 --- a/xml/System/DateTime.xml +++ b/xml/System/DateTime.xml @@ -4491,7 +4491,7 @@ This overload attempts to parse `s` by using A string that contains a date and time to convert. See [The string to parse](#StringToParse) for more information. - An object that supplies culture-specific format information about s. See [Parsing and cultural conventions](#Culture) + An object that supplies culture-specific format information about s. See [Parsing and cultural conventions](#Culture) Converts the string representation of a date and time to its equivalent by using culture-specific format information. An object that is equivalent to the date and time contained in as specified by . @@ -4546,7 +4546,7 @@ This overload attempts to parse `s` by using A string that contains a date and time to convert. See [The string to parse](#StringToParse) for more information. - An object that supplies culture-specific formatting information about s. See [Parsing and cultural conventions](#Culture) + An object that supplies culture-specific formatting information about s. See [Parsing and cultural conventions](#Culture) A bitwise combination of the enumeration values that indicates the style elements that can be present in s for the parse operation to succeed, and that defines how to interpret the parsed date in relation to the current time zone or the current date. A typical value to specify is . Converts the string representation of a date and time to its equivalent by using culture-specific format information and a formatting style. An object that is equivalent to the date and time contained in , as specified by and . From 4d882f14fc56d2248a8344b35d8a01e85af7e92c Mon Sep 17 00:00:00 2001 From: Ron Petrusha Date: Fri, 2 Mar 2018 16:54:31 -0800 Subject: [PATCH 6/9] Moved examples --- xml/System/DateTime.xml | 58 +++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/xml/System/DateTime.xml b/xml/System/DateTime.xml index a5365f6e8a2f3..714aec0e1e9e5 100644 --- a/xml/System/DateTime.xml +++ b/xml/System/DateTime.xml @@ -4241,11 +4241,7 @@ juillet 2009 [Parsing and cultural conventions](#Culture) [Parsing and style elements](#Styles) [The return value and DateTime.Kind](#kind) - Examples: - [DateTime.Parse(String)](#Parse1_Example) - [DateTime.Parse(String, IFormatProvider)](#Parse2_Example) - [DateTime.Parse(String, IFormatProvider, DateTimeStyles)](#Parse3_Example) - + ### Which method do I call? @@ -4379,27 +4375,6 @@ Numerous examples that call the `DateTime.Parse` method are interspersed through You can also download a complete set of `DateTime.Parse` examples, which are included in a [.NET Core 2.0 project for C#]() and a [.NET Core 2.0 project for Visual Basic](), from the [dotnet/docs GitHub repository](https://github.com/dotnet/docs). - -## DateTime.Parse(String) example - The following example parses the string representation of several date and time values by using default provider and style values: the formatting conventions of the en-US culture, which is the current thread culture of the computer used to produce the example output, and the style flag. It handles the exception that is thrown when the method tries to parse the string representation of a date and time by using some other culture's formatting conventions. It also shows how to successfully parse a date and time value that does not use the formatting conventions of the current thread culture. - - [!code-csharp-interactive[System.DateTime.Parse#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse1.cs#1)] - [!code-vb[System.DateTime.Parse#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse1.vb#1)] - - -## DateTime.Parse(String, IFormatProvider) example - The following example parses an array of date strings by using the conventions of the en-US, fr-FR, and de-DE cultures. It demonstrates that the string representations of a single date can be interpreted differently across different cultures. - - [!code-csharp-interactive[System.DateTime.Parse#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse3.cs#3)] - [!code-vb[System.DateTime.Parse#3](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse3.vb#3)] - - -## DateTime.Parse(String, IFormatProvider, DateTimeStyles) example - The following example demonstrates the method and displays the value of the property of the resulting values. - - [!code-csharp-interactive[System.DateTime.Parse#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse4.cs#4)] - [!code-vb[System.DateTime.Parse#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse4.vb#4)] - ]]> @@ -4448,7 +4423,20 @@ If `s` contains time zone information, this method returns a property. To parse a string using the formatting conventions of a specific culture, call the or the overloads. This overload attempts to parse `s` by using style. - + +## Example + +The following example parses the string representation of several date and time values by: + +- Using the default format provider, which provides the formatting conventions of hte current thread culture of the computer used to produce the example output. The output from this example reflects the formatting conventions of the en-US culture. + +- Using the default style value, which is . + +It handles the exception that is thrown when the method tries to parse the string representation of a date and time by using some other culture's formatting conventions. It also shows how to successfully parse a date and time value that does not use the formatting conventions of the current thread culture. + + [!code-csharp-interactive[System.DateTime.Parse#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse1.cs#1)] + [!code-vb[System.DateTime.Parse#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse1.vb#1)] + ]]> @@ -4501,8 +4489,15 @@ This overload attempts to parse `s` by using value whose property is and converts the date and time in `s` to local time. Otherwise, it performs no time zone conversion and returns a value whose property is . -This overload attempts to parse `s` by using style. +This overload attempts to parse `s` by using the style. +## Example + +The following example parses an array of date strings by using the conventions of the en-US, fr-FR, and de-DE cultures. It demonstrates that the string representations of a single date can be interpreted differently across different cultures. + +[!code-csharp-interactive[System.DateTime.Parse#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse3.cs#3)] +[!code-vb[System.DateTime.Parse#3](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse3.vb#3)] + ]]> @@ -4564,6 +4559,13 @@ This method overload converts the date and time in `s` and sets the flag.|To Coordinated Univeral Time (UTC)|| |`s` contains the Z or GMT time zone designator, and `styles` includes the .|None.|| +## Example + +The following example demonstrates the method and displays the value of the property of the resulting values. + +[!code-csharp-interactive[System.DateTime.Parse#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse4.cs#4)] +[!code-vb[System.DateTime.Parse#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse4.vb#4)] + ]]> From b559a30ef6f79ab8ab74d04acfc64e92a172c22f Mon Sep 17 00:00:00 2001 From: Ron Petrusha Date: Mon, 5 Mar 2018 16:17:33 -0800 Subject: [PATCH 7/9] Additional revisions and .zip files --- .../system.DateTime.Parse/cs/Parse6.cs | 38 +++++++++++++++ .../downloads/api/System/DateTime.Parse.zip | Bin 0 -> 5356 bytes .../system.DateTime.Parse/vb/Parse2.vb | 12 ++--- .../system.DateTime.Parse/vb/Parse3.vb | 2 +- .../system.DateTime.Parse/vb/Parse5.vb | 45 ------------------ .../system.DateTime.Parse/vb/Parse6.vb | 35 ++++++++++++++ .../downloads/api/System/DateTime.Parse.zip | Bin 0 -> 5430 bytes xml/System/DateTime.xml | 25 ++++++---- 8 files changed, 95 insertions(+), 62 deletions(-) create mode 100644 samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse6.cs create mode 100644 samples/snippets/csharp/downloads/api/System/DateTime.Parse.zip delete mode 100644 samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse5.vb create mode 100644 samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse6.vb create mode 100644 samples/snippets/visualbasic/downloads/api/System/DateTime.Parse.zip diff --git a/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse6.cs b/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse6.cs new file mode 100644 index 0000000000000..b8b69ce5bc4c7 --- /dev/null +++ b/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse6.cs @@ -0,0 +1,38 @@ +using System; + +public class Example +{ + public static void Main() + { + ValueTuple[] dateInfo = { ("08/18/2018 07:22:16", "String with a date and time component"), + ("08/18/2018", "String with a date component only"), + ("8/2018", "String with a month and year component only"), + ("8/18", "String with a month and day component only"), + ("07:22:16", "String with a time component only"), + ("7 PM", "String with an hour and AM/PM designator only"), + ("2018-08-18T07:22:16.0000000Z", "UTC string that conforms to ISO 8601"), + ("2018-08-18T07:22:16.0000000-07:00", "Non-UTC string that conforms to ISO 8601"), + ("Sat, 18 Aug 2018 07:22:16 GMT", "String that conforms to RFC 1123"), + ("08/18/2018 07:22:16 -5:00", "String with date, time, and time zone information" ) }; + + Console.WriteLine($"Today is {DateTime.Now:d}\n"); + + foreach (var item in dateInfo) { + Console.WriteLine($"{item.Item2 + ":",-52} '{item.Item1}' --> {DateTime.Parse(item.Item1)}"); + } + } +} +// The example displays output like the following: +// Today is 2/22/2018 +// +// String with a date and time component: '08/18/2018 07:22:16' --> 8/18/2018 7:22:16 AM +// String with a date component only: '08/18/2018' --> 8/18/2018 12:00:00 AM +// String with a month and year component only: '8/2018' --> 8/1/2018 12:00:00 AM +// String with a month and day component only: '8/18' --> 8/18/2018 12:00:00 AM +// String with a time component only: '07:22:16' --> 2/22/2018 7:22:16 AM +// String with an hour and AM/PM designator only: '7 PM' --> 2/22/2018 7:00:00 PM +// UTC string that conforms to ISO 8601: '2018-08-18T07:22:16.0000000Z' --> 8/18/2018 12:22:16 AM +// Non-UTC string that conforms to ISO 8601: '2018-08-18T07:22:16.0000000-07:00' --> 8/18/2018 7:22:16 AM +// String that conforms to RFC 1123: 'Sat, 18 Aug 2018 07:22:16 GMT' --> 8/18/2018 12:22:16 AM +// String with date, time, and time zone information: '08/18/2018 07:22:16 -5:00' --> 8/18/2018 5:22:16 AM + diff --git a/samples/snippets/csharp/downloads/api/System/DateTime.Parse.zip b/samples/snippets/csharp/downloads/api/System/DateTime.Parse.zip new file mode 100644 index 0000000000000000000000000000000000000000..028fcf75e79d9a4467942b0a1b4822462008887b GIT binary patch literal 5356 zcmZ{obyQSs*TzRmx&@^LDPd@o8cIN7=#Yj%hLAyE7>8~UNog1a1ft5&V{oD7xbTn}BXaN8KAt2US6KtA2W$S}|tHfS6 zu$L_a0Yx}ELj_zRaCfM{V|Q1$%abZ1o`Df{O#xj(t^QiW!y&N1fZ(t;-^cInWFK*f zd1nvc2XJ1V89?%lJi26qM*6i>x|yKRz~IY#PW*h%+sXLFNc4^3duOV?MUipcxknS! zb-CRO6NeYMu%_mTgw>1OiSA$=4iGM*AHuQR@N5Hl01xVsAI3Wb==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p$>+3GmIyNELshGs))!hV=H7;BHpS>$cjg?qnEH}sN#^)N`uy-5o)+~A9^wT|LZ~hss5W$@LMg3ZI1t?{?j)2 zGtA#+tKVTX34Vw9&!qLI_;1_c-{NWPsP=nv{HN}3ZTz?H5w__5yQ%-F{ad5?tv$e6 sCVy``f5!M*mH&=WkG22)u~`07^Ew*%*w66G)g%NQW4W+I{p;<20ERz_@&Et; literal 0 HcmV?d00001 diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse2.vb b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse2.vb index b2dddbd3ade57..ad8458fe5cba7 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse2.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse2.vb @@ -4,15 +4,15 @@ Option Strict On ' Module Example Public Sub Main() - Dim dateStrings() As String = {"2008-05-01T07:34:42-5:00", _ - "2008-05-01 7:34:42Z", _ + Dim dateStrings() As String = {"2008-05-01T07:34:42-5:00", + "2008-05-01 7:34:42Z", "Thu, 01 May 2008 07:34:42 GMT"} - For Each dateString As String In dateStrings + For Each dateString In dateStrings Dim convertedDate As Date = Date.Parse(dateString) - Console.WriteLine("Converted {0} to {1} time {2}", _ - dateString, _ - convertedDate.Kind.ToString(), _ + Console.WriteLine("Converted {0} to {1} time {2}", + dateString, + convertedDate.Kind.ToString(), convertedDate) Next End Sub diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse3.vb b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse3.vb index 5029d4e44849c..9c9ee3ee2525d 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse3.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse3.vb @@ -15,7 +15,7 @@ Module ParseDate "10.01.2009 19:34", _ "10-1-2009 19:34" } ' Parse dates using each culture. - For Each culture As CultureInfo In cultures + For Each culture In cultures Dim dateValue As Date Console.WriteLine("Attempted conversions using {0} culture.", culture.Name) For Each dateString As String In dateStrings diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse5.vb b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse5.vb deleted file mode 100644 index 30ba331026a56..0000000000000 --- a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse5.vb +++ /dev/null @@ -1,45 +0,0 @@ -' Visual Basic .NET Document -Option Strict On - -Imports System.Globalization - - -Module modMain - Public Sub Main() - ' - Dim formattedDates() As String = { "2008-09-15T09:30:41.7752486-07:00", _ - "2008-09-15T09:30:41.7752486Z", _ - "2008-09-15T09:30:41.7752486", _ - "2008-09-15T09:30:41.7752486-04:00", _ - "Mon, 15 Sep 2008 09:30:41 GMT" } - For Each formattedDate As String In formattedDates - Console.WriteLine(formattedDate) - Dim roundtripDate As Date = Date.Parse(formattedDate, Nothing, _ - DateTimeStyles.RoundtripKind) - Console.WriteLine(" With RoundtripKind flag: {0} {1} time.", _ - roundtripDate, roundtripDate.Kind) - Dim noRoundtripDate As Date = Date.Parse(formattedDate, Nothing, _ - DateTimeStyles.None) - Console.WriteLine(" Without RoundtripKind flag: {0} {1} time.", _ - noRoundtripDate, noRoundtripDate.Kind) - Next - ' The example displays the following output: - ' 2008-09-15T09:30:41.7752486-07:00 - ' With RounndtripKind flag: 9/15/2008 9:30:41 AM Local time. - ' Without RoundtripKind flag: 9/15/2008 9:30:41 AM Local time. - ' 2008-09-15T09:30:41.7752486Z - ' With RounndtripKind flag: 9/15/2008 9:30:41 AM Utc time. - ' Without RoundtripKind flag: 9/15/2008 2:30:41 AM Local time. - ' 2008-09-15T09:30:41.7752486 - ' With RounndtripKind flag: 9/15/2008 9:30:41 AM Unspecified time. - ' Without RoundtripKind flag: 9/15/2008 9:30:41 AM Unspecified time. - ' 2008-09-15T09:30:41.7752486-04:00 - ' With RounndtripKind flag: 9/15/2008 6:30:41 AM Local time. - ' Without RoundtripKind flag: 9/15/2008 6:30:41 AM Local time. - ' Mon, 15 Sep 2008 09:30:41 GMT - ' With RounndtripKind flag: 9/15/2008 9:30:41 AM Utc time. - ' Without RoundtripKind flag: 9/15/2008 2:30:41 AM Local time. - ' - End Sub -End Module - diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse6.vb b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse6.vb new file mode 100644 index 0000000000000..f3e2f5350e05b --- /dev/null +++ b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse6.vb @@ -0,0 +1,35 @@ + +Public Module Strings + Public Sub Main() + Dim dateInfo() As ValueTuple(Of String, String) = { ("08/18/2018 07:22:16", "String with a date and time component"), + ("08/18/2018", "String with a date component only"), + ("8/2018", "String with a month and year component only"), + ("8/18", "String with a month and day component only"), + ("07:22:16", "String with a time component only"), + ("7 PM", "String with an hour and AM/PM designator only"), + ("2018-08-18T07:22:16.0000000Z", "UTC string that conforms to ISO 8601"), + ("2018-08-18T07:22:16.0000000-07:00", "Non-UTC string that conforms to ISO 8601"), + ("Sat, 18 Aug 2018 07:22:16 GMT", "String that conforms to RFC 1123"), + ("08/18/2018 07:22:16 -5:00", "String with date, time, and time zone information" ) } + + Console.WriteLine($"Today is {Date.Now:d}{vbCrLf}") + + For Each item in dateInfo + Console.WriteLine($"{item.Item2 + ":",-52} '{item.Item1}' --> {DateTime.Parse(item.Item1)}") + Next + End Sub +End Module +' The example displays output like the following: +' Today is 2/22/2018 +' +' String with a date and time component: '08/18/2018 07:22:16' --> 8/18/2018 7:22:16 AM +' String with a date component only: '08/18/2018' --> 8/18/2018 12:00:00 AM +' String with a month and year component only: '8/2018' --> 8/1/2018 12:00:00 AM +' String with a month and day component only: '8/18' --> 8/18/2018 12:00:00 AM +' String with a time component only: '07:22:16' --> 2/22/2018 7:22:16 AM +' String with an hour and AM/PM designator only: '7 PM' --> 2/22/2018 7:00:00 PM +' UTC string that conforms to ISO 8601: '2018-08-18T07:22:16.0000000Z' --> 8/18/2018 12:22:16 AM +' Non-UTC string that conforms to ISO 8601: '2018-08-18T07:22:16.0000000-07:00' --> 8/18/2018 7:22:16 AM +' String that conforms to RFC 1123: 'Sat, 18 Aug 2018 07:22:16 GMT' --> 8/18/2018 12:22:16 AM +' String with date, time, and time zone information: '08/18/2018 07:22:16 -5:00' --> 8/18/2018 5:22:16 AM + diff --git a/samples/snippets/visualbasic/downloads/api/System/DateTime.Parse.zip b/samples/snippets/visualbasic/downloads/api/System/DateTime.Parse.zip new file mode 100644 index 0000000000000000000000000000000000000000..0112cc2988f222569616cca53c041d527f2083b3 GIT binary patch literal 5430 zcmZ`-2Q*y$w;dz8=)DC|hKWuDAtAcadr2^&L=Q5A83ZB1kYIvIqKw`niRhz-2+>6u zy#>*UUf$$;?|brpEAOs**Ijq5yU+ct`#XD|bGCsF;UxwD06+?8vowQPWqiLMgnxRE zzbNsSx4n6@LUN(eEuSqP zA2=~8KH~5JxfsG2xT)6alBa@edimU z!h6n)J157bZv}L%<$=xmace>Fp6Yg4y$xQmh(U5pPQUbigELf5axd9MplZN3Fqv0K zirfLS9J}DBosH4ZqXy(I+;osoUEo+<5gCXX&AO53?>aq7f8$6zS7?r5R&pRGoBU&_ z+*6~zRtN<>85suL5XbtVPEKia8q$=1R5M)=Y8>E+IJ&AOaYNXp%ZRBAMl8C}^7_j! zstjU;uOC2nVe@3zIb6W+Mq1TmXB<>pr)}eQKk!k84K4vhBSZrp(bg)md(V?Lige%A zZdhs2{6Rcp&%(h))Fc5{INWB;P4;wF@?<$sUcyapvSdv$%2P&_Xu8m*mFkAJiKiOT ziMdis4|YF|&~kIYu`<_{>w=4{UQF?UJ)V{OxP?Sup2r?lCOkN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_SG;z@kDt?9hI!lZ4jR2~mMhu2_Wp;nG;g(X zj@wB2hmFh{pmpG{w}m;&o)#|W$M4kHErQq$j!M>PPbCMvyL9%szqy)JEY6mck5vp7 z872hr28;rZhZqWKo@Fec-)=Xv7V3S;lN`Pxt*^M`4ptD#&GbNok0t;PTMdh&95fxf zHnqe0V<_-)m8g5;uGbskTb-g9*x0GgQ%*v&OYC3^i3{ZEwwY{lAp5HNXpSe?+V+P#Lg;glI=<;RWM2~_tf^XG57s* zd3;(B02u)PziEcg4FCav`}Ylh{Ar>6iTs;iTztG rxxiZBtNY(8%bzj+#^s9`9JK$*Yy%x4{BQW}kCFm@vtNq-_tSp?66uz_ literal 0 HcmV?d00001 diff --git a/xml/System/DateTime.xml b/xml/System/DateTime.xml index 714aec0e1e9e5..2ce210df4e55a 100644 --- a/xml/System/DateTime.xml +++ b/xml/System/DateTime.xml @@ -4273,20 +4273,27 @@ juillet 2009 - A string with a date component that includes only the month and the day but no year component. The method assumes the current year. -- A string with a time but no date component. The method assumes the current date unless you call the overload and include in the `styles` argument, in which case the method assumes January 1, 0001. - -- A string that includes time zone information and conforms to ISO 8601. In the following examples, the first string designates Coordinated Universal Time (UTC), and the second string designates the time in a time zone that's seven hours earlier than UTC: +- A string with a time but no date component. The method assumes the current date unless you call the overload and include in the `styles` argument, in which case the method assumes a date of January 1, 0001. + +- A string with a time component that includes only the hour and an AM/PM designator, with no date component. The method assumes the current date and a time with no minutes and no seconds. You can change this behavior by calling the overload and include in the `styles` argument, in which case the method assumes a date of January 1, 0001. + +- A string that includes time zone information and conforms to ISO 8601. In the following examples, the first string designates Coordinated Universal Time (UTC), and the second designates the time in a time zone that's seven hours earlier than UTC: - 2008-11-01T19:35:00.0000000Z - 2008-11-01T19:35:00.0000000-07:00 + "2008-11-01T19:35:00.0000000Z" + "2008-11-01T19:35:00.0000000-07:00" - A string that includes the GMT designator and conforms to the RFC 1123 time format; for example: - Sat, 01 Nov 2008 19:35:00 GMT + "Sat, 01 Nov 2008 19:35:00 GMT" - A string that includes the date and time along with time zone offset information; for example: - 03/01/2009 05:42:00 -5:00 + "03/01/2009 05:42:00 -5:00" + +The following example parses strings in each of these formats by using the formatting conventions of the current culture, which in this case is the en-US culture: + +[!code-csharp-interactive[Default parsing](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse6.cs)] +[!code-vb[Default parsing](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse6.vb)] If `s` is the string representation of a leap day in a leap year in the calendar used by the parsing method (see [Parsing and cultural conventions](#Culture)), the method parses `s` successfully. If `s` is the string representation of a leap day in a non-leap year, the method throws a . @@ -4359,8 +4366,6 @@ The `DateTime.Parse` overloads return a value whose property during a formatting and parsing operation by using the flag. The following example illustrates how the flag affects the parsing operation on values that are converted to strings by using the "o", "r", or "u" format specifier. [!code-csharp-interactive[System.DateTime.Parse#5](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse5.cs#5)] @@ -4373,7 +4378,7 @@ Numerous examples that call the `DateTime.Parse` method are interspersed through > [!NOTE] > The C# examples in this article run in the [Try.NET](https://try.dot.net) inline code runner and playground. You can run an example in an interactive window by pressing the **Run** button. Once you execute the code, you can modify it and run the modified code by pressing **Run** again. The modified code either runs in the interactive window or, if compilation fails, the interactive window displays all C# compiler error messages. -You can also download a complete set of `DateTime.Parse` examples, which are included in a [.NET Core 2.0 project for C#]() and a [.NET Core 2.0 project for Visual Basic](), from the [dotnet/docs GitHub repository](https://github.com/dotnet/docs). +You can also download a complete set of `DateTime.Parse` examples, which are included in a [.NET Core 2.0 project for C#](~/samples/snippets/csharp/downloads/api/System/DateTime.Parse.zip) and a [.NET Core 2.0 project for Visual Basic](~/samples/snippets/visualbasic/downloads/api/System.DateTime.Parse.zip), from the [dotnet/docs GitHub repository](https://github.com/dotnet/docs). ]]> From 4a8ae35e1d6e45e471037628f7e60107b93c3f36 Mon Sep 17 00:00:00 2001 From: Ron Petrusha Date: Tue, 6 Mar 2018 08:11:22 -0800 Subject: [PATCH 8/9] Added accidentally deleted file --- .../system.DateTime.Parse/vb/Parse5.vb | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse5.vb diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse5.vb b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse5.vb new file mode 100644 index 0000000000000..28da640d38751 --- /dev/null +++ b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse5.vb @@ -0,0 +1,42 @@ + +Imports System.Globalization + + +Public Module Class1 + Public Sub Main() + ' + Dim formattedDates() = { "2008-09-15T09:30:41.7752486-07:00", + "2008-09-15T09:30:41.7752486Z", + "2008-09-15T09:30:41.7752486", + "2008-09-15T09:30:41.7752486-04:00", + "Mon, 15 Sep 2008 09:30:41 GMT" } + For Each formattedDate In formattedDates + Console.WriteLine(formattedDate) + Dim roundtripDate = DateTime.Parse(formattedDate, Nothing, + DateTimeStyles.RoundtripKind) + Console.WriteLine(" With RoundtripKind flag: {0} {1} time.", + roundtripDate, roundtripDate.Kind) + Dim noRoundtripDate = DateTime.Parse(formattedDate, Nothing, + DateTimeStyles.None) + Console.WriteLine(" Without RoundtripKind flag: {0} {1} time.", + noRoundtripDate, noRoundtripDate.Kind) + Next + ' The example displays the following output: + ' 2008-09-15T09:30:41.7752486-07:00 + ' With RoundtripKind flag: 9/15/2008 9:30:41 AM Local time. + ' Without RoundtripKind flag: 9/15/2008 9:30:41 AM Local time. + ' 2008-09-15T09:30:41.7752486Z + ' With RoundtripKind flag: 9/15/2008 9:30:41 AM Utc time. + ' Without RoundtripKind flag: 9/15/2008 2:30:41 AM Local time. + ' 2008-09-15T09:30:41.7752486 + ' With RoundtripKind flag: 9/15/2008 9:30:41 AM Unspecified time. + ' Without RoundtripKind flag: 9/15/2008 9:30:41 AM Unspecified time. + ' 2008-09-15T09:30:41.7752486-04:00 + ' With RoundtripKind flag: 9/15/2008 6:30:41 AM Local time. + ' Without RoundtripKind flag: 9/15/2008 6:30:41 AM Local time. + ' Mon, 15 Sep 2008 09:30:41 GMT + ' With RoundtripKind flag: 9/15/2008 9:30:41 AM Utc time. + ' Without RoundtripKind flag: 9/15/2008 2:30:41 AM Local time. + ' + End Sub +End Module From c9f63f7d710068682d8db32c5313dc042b9e01e5 Mon Sep 17 00:00:00 2001 From: Ron Petrusha Date: Tue, 13 Mar 2018 13:16:39 -0700 Subject: [PATCH 9/9] Addressed review comments --- .../system.DateTime.Parse/cs/Parse2.cs | 5 +--- .../system.DateTime.Parse/cs/Parse5.cs | 7 +++--- .../system.DateTime.Parse/cs/Parse6.cs | 22 ++++++++--------- .../downloads/api/System/DateTime.Parse.zip | Bin 5356 -> 5372 bytes .../system.DateTime.Parse/vb/Parse2.vb | 9 +++---- .../system.DateTime.Parse/vb/Parse5.vb | 12 +++------ .../system.DateTime.Parse/vb/Parse6.vb | 23 +++++++++--------- .../downloads/api/System/DateTime.Parse.zip | Bin 5430 -> 5430 bytes xml/System/DateTime.xml | 17 ++++++------- 9 files changed, 42 insertions(+), 53 deletions(-) diff --git a/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse2.cs b/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse2.cs index a09548c48a44c..1be2590f2c71e 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse2.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse2.cs @@ -11,10 +11,7 @@ public static void Main() foreach (string dateString in dateStrings) { DateTime convertedDate = DateTime.Parse(dateString); - Console.WriteLine("Converted {0} to {1} time {2}", - dateString, - convertedDate.Kind.ToString(), - convertedDate); + Console.WriteLine($"Converted {dateString} to {convertedDate.Kind} time {convertedDate}"); } } } diff --git a/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse5.cs b/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse5.cs index eb2c50fbf71d4..92c4779d1c6bb 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse5.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse5.cs @@ -17,12 +17,11 @@ public static void Main() Console.WriteLine(formattedDate); DateTime roundtripDate = DateTime.Parse(formattedDate, null, DateTimeStyles.RoundtripKind); - Console.WriteLine(" With RoundtripKind flag: {0} {1} time.", - roundtripDate, roundtripDate.Kind); + Console.WriteLine($" With RoundtripKind flag: {roundtripDate} {roundtripDate.Kind} time."); + DateTime noRoundtripDate = DateTime.Parse(formattedDate, null, DateTimeStyles.None); - Console.WriteLine(" Without RoundtripKind flag: {0} {1} time.", - noRoundtripDate, noRoundtripDate.Kind); + Console.WriteLine($" Without RoundtripKind flag: {noRoundtripDate} {noRoundtripDate.Kind} time."); } // The example displays the following output: // 2008-09-15T09:30:41.7752486-07:00 diff --git a/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse6.cs b/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse6.cs index b8b69ce5bc4c7..2f0711dbb77c0 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse6.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse6.cs @@ -4,21 +4,21 @@ public class Example { public static void Main() { - ValueTuple[] dateInfo = { ("08/18/2018 07:22:16", "String with a date and time component"), - ("08/18/2018", "String with a date component only"), - ("8/2018", "String with a month and year component only"), - ("8/18", "String with a month and day component only"), - ("07:22:16", "String with a time component only"), - ("7 PM", "String with an hour and AM/PM designator only"), - ("2018-08-18T07:22:16.0000000Z", "UTC string that conforms to ISO 8601"), - ("2018-08-18T07:22:16.0000000-07:00", "Non-UTC string that conforms to ISO 8601"), - ("Sat, 18 Aug 2018 07:22:16 GMT", "String that conforms to RFC 1123"), - ("08/18/2018 07:22:16 -5:00", "String with date, time, and time zone information" ) }; + (string dateAsString, string description)[] dateInfo = { ("08/18/2018 07:22:16", "String with a date and time component"), + ("08/18/2018", "String with a date component only"), + ("8/2018", "String with a month and year component only"), + ("8/18", "String with a month and day component only"), + ("07:22:16", "String with a time component only"), + ("7 PM", "String with an hour and AM/PM designator only"), + ("2018-08-18T07:22:16.0000000Z", "UTC string that conforms to ISO 8601"), + ("2018-08-18T07:22:16.0000000-07:00", "Non-UTC string that conforms to ISO 8601"), + ("Sat, 18 Aug 2018 07:22:16 GMT", "String that conforms to RFC 1123"), + ("08/18/2018 07:22:16 -5:00", "String with date, time, and time zone information" ) }; Console.WriteLine($"Today is {DateTime.Now:d}\n"); foreach (var item in dateInfo) { - Console.WriteLine($"{item.Item2 + ":",-52} '{item.Item1}' --> {DateTime.Parse(item.Item1)}"); + Console.WriteLine($"{item.description + ":",-52} '{item.dateAsString}' --> {DateTime.Parse(item.dateAsString)}"); } } } diff --git a/samples/snippets/csharp/downloads/api/System/DateTime.Parse.zip b/samples/snippets/csharp/downloads/api/System/DateTime.Parse.zip index 028fcf75e79d9a4467942b0a1b4822462008887b..c9d60f6f3093e113e13032c38d55c8a6eff05162 100644 GIT binary patch delta 2692 zcmZuzWmFRk7alRC#$b$;FaQOK(Ip`r`;eIAC=rktp@8%dfq{s`Xc$O|q;%u!kQ7NL zC?VZ7V03-F=lk)V_nhyZd+v{Wo^yZPcIz^(7UlMS=U_{>1n@1y36y3cYL$__<&_7gH3Fa9xvZsM5NyvL^}H6Bjjoa z7(Bq%*D>8Te^Hn$o!52oad#cizf*BAGO6740J`)>VRy?QYNZD=?4Ael*>Xa3JgVJ{ z51fc5nN`4GTKDie>ms{Q*iLh#A-JObQwk8BtK)G897rcJ?4X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ipt(9{_&Nw`?vparo>87v z&f&&+SbnFB9pb365=A~&49b_{Z2Mn}@DOZ-dPWEPzx%Y-r1<8S49Y}#j}7ynf+#oV zl%PYph9NB$u%V_%R-0Lk4{^KR^x2_^ci1rbQAq5R-fS-x`U+*7*8!RvO|1Qz7c0f!Z@#E=8a0H8p{VNcUKSrUy e3CHzc&K7|HmKOVe0{n;5NSFkRotzW+8~G24p#kjx diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse2.vb b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse2.vb index ad8458fe5cba7..709ca366c209f 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse2.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse2.vb @@ -8,12 +8,9 @@ Module Example "2008-05-01 7:34:42Z", "Thu, 01 May 2008 07:34:42 GMT"} - For Each dateString In dateStrings - Dim convertedDate As Date = Date.Parse(dateString) - Console.WriteLine("Converted {0} to {1} time {2}", - dateString, - convertedDate.Kind.ToString(), - convertedDate) + For Each dateStr In dateStrings + Dim convertedDate As Date = Date.Parse(dateStr) + Console.WriteLine($"Converted {dateStr} to {convertedDate.Kind} time {convertedDate}") Next End Sub End Module diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse5.vb b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse5.vb index 28da640d38751..f100906c05721 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse5.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse5.vb @@ -1,7 +1,6 @@ Imports System.Globalization - Public Module Class1 Public Sub Main() ' @@ -13,13 +12,10 @@ Public Module Class1 For Each formattedDate In formattedDates Console.WriteLine(formattedDate) Dim roundtripDate = DateTime.Parse(formattedDate, Nothing, - DateTimeStyles.RoundtripKind) - Console.WriteLine(" With RoundtripKind flag: {0} {1} time.", - roundtripDate, roundtripDate.Kind) - Dim noRoundtripDate = DateTime.Parse(formattedDate, Nothing, - DateTimeStyles.None) - Console.WriteLine(" Without RoundtripKind flag: {0} {1} time.", - noRoundtripDate, noRoundtripDate.Kind) + DateTimeStyles.RoundtripKind) + Console.WriteLine($" With RoundtripKind flag: {roundtripDate} {roundtripDate.Kind} time.") + Dim noRoundtripDate = DateTime.Parse(formattedDate, Nothing, DateTimeStyles.None) + Console.WriteLine($" Without RoundtripKind flag: {noRoundtripDate} {noRoundtripDate.Kind} time.") Next ' The example displays the following output: ' 2008-09-15T09:30:41.7752486-07:00 diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse6.vb b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse6.vb index f3e2f5350e05b..5cebde44082f2 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse6.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse6.vb @@ -1,21 +1,22 @@ Public Module Strings Public Sub Main() - Dim dateInfo() As ValueTuple(Of String, String) = { ("08/18/2018 07:22:16", "String with a date and time component"), - ("08/18/2018", "String with a date component only"), - ("8/2018", "String with a month and year component only"), - ("8/18", "String with a month and day component only"), - ("07:22:16", "String with a time component only"), - ("7 PM", "String with an hour and AM/PM designator only"), - ("2018-08-18T07:22:16.0000000Z", "UTC string that conforms to ISO 8601"), - ("2018-08-18T07:22:16.0000000-07:00", "Non-UTC string that conforms to ISO 8601"), - ("Sat, 18 Aug 2018 07:22:16 GMT", "String that conforms to RFC 1123"), - ("08/18/2018 07:22:16 -5:00", "String with date, time, and time zone information" ) } + Dim dateInfo() As (dateAsString As String, description As String) = + { ("08/18/2018 07:22:16", "String with a date and time component"), + ("08/18/2018", "String with a date component only"), + ("8/2018", "String with a month and year component only"), + ("8/18", "String with a month and day component only"), + ("07:22:16", "String with a time component only"), + ("7 PM", "String with an hour and AM/PM designator only"), + ("2018-08-18T07:22:16.0000000Z", "UTC string that conforms to ISO 8601"), + ("2018-08-18T07:22:16.0000000-07:00", "Non-UTC string that conforms to ISO 8601"), + ("Sat, 18 Aug 2018 07:22:16 GMT", "String that conforms to RFC 1123"), + ("08/18/2018 07:22:16 -5:00", "String with date, time, and time zone information" ) } Console.WriteLine($"Today is {Date.Now:d}{vbCrLf}") For Each item in dateInfo - Console.WriteLine($"{item.Item2 + ":",-52} '{item.Item1}' --> {DateTime.Parse(item.Item1)}") + Console.WriteLine($"{item.description + ":",-52} '{item.dateAsString}' --> {DateTime.Parse(item.dateAsString)}") Next End Sub End Module diff --git a/samples/snippets/visualbasic/downloads/api/System/DateTime.Parse.zip b/samples/snippets/visualbasic/downloads/api/System/DateTime.Parse.zip index 0112cc2988f222569616cca53c041d527f2083b3..7bc2ca0f92e1ff200a58eb083eca1cf07594efb2 100644 GIT binary patch delta 2259 zcmV;^2rT!uDz+-HFbRKSW^GLDs~HxD0{{T!3IG5K0001Ra&KpHVQnsUVzpM$ZW=of zeMjOSMypDJlv+)4Zy%ykDIz37O;Z$5t3F*Bb^xopHnP1WTg1P2Z12J@A#Iwg`T^~l z<1=%{p0ggLOQo%WQEn`ztf!I$r&cIw*fmPjV%lsB>X_?9O?ZDIesBkCHkyr3D$Wvw zA=d``4?JBaXqpY6G1OwkEdmy^aADvh=3jV{;gAd6`aFY?)k4lYaN)zYTkZPN)Xd$g zfPyaED!ZVk01CgOYy!7;l1r*jB*=Vd+%H z5#i%lqcK|s!+d`M+MPcSc*@`oZKfrx9Pk{*6!ntSk41{?qmVHywOXRKc`a~Q z1eCs{MI2<7PEeEc*?U9@Z-G-K*QLR-8g=`iP>cJnt%Eo&VP+ZHb_ z5LbVh3?<#~-rcpLy?fj;mwEOQ2khd z{XOAZKv4*Qr~{mM7*@>NF^VZyx>}W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ma|oGL%dE~0kY{Y!-%16BkZU3r76e6Me}`rQ~_M1WbLVFhNN z^2Y-mnyTk8u>Pfj#+-Z2IiE$D%a{aoK}pz{`f+fzUyGB=xW1HM>VOV@l}@JpUky_r zWdAx}vojM10S#(?WlV;kyd;MM006y{M-*ocW@J`OfB1B_kOBYzstS|56gD3%cV$fT hx{Olo0RR9F2><{L000000000103ZMW034GM6(t-&Nwoj~ diff --git a/xml/System/DateTime.xml b/xml/System/DateTime.xml index 2ce210df4e55a..21c8a7c267b33 100644 --- a/xml/System/DateTime.xml +++ b/xml/System/DateTime.xml @@ -4258,11 +4258,11 @@ juillet 2009 ### The string to parse - The method tries to convert the string representation of a date and time value to its equivalent. It tries to parse `s` completely without throwing a exception. + The method tries to convert the string representation of a date and time value to its equivalent. It tries to parse the input string completely without throwing a exception. > [!IMPORTANT] -> Because the string representation of a date and time must conform to a recognized pattern, you should always use exception handling when calling the method to parse user input. If you don't want to handle exceptions, you can call the method to parse the date and time string; this method returns a value that indicates whether the parse operation succeeded. - +> If the parsing operation fails because of an unrecognized string format, the method throws a , whereas the method returns `false`. Because exception handling can be expensive, you should use when the parsing operation is expected to succeed because the input source is trusted. is preferable when parsing failures are likely, particularly because an input source is not trusted, or you have reasonable default values to substitute for strings that do not parse successfully. + The string to be parsed can take any of the following forms: - A string with a date and a time component. @@ -4295,13 +4295,13 @@ The following example parses strings in each of these formats by using the forma [!code-csharp-interactive[Default parsing](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse6.cs)] [!code-vb[Default parsing](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse6.vb)] - If `s` is the string representation of a leap day in a leap year in the calendar used by the parsing method (see [Parsing and cultural conventions](#Culture)), the method parses `s` successfully. If `s` is the string representation of a leap day in a non-leap year, the method throws a . + If the input string represents a leap day in a leap year in the calendar used by the parsing method (see [Parsing and cultural conventions](#Culture)), the method parses the string successfully. If the input string represents a leap day in a non-leap year, the method throws a . Because the method tries to parse the string representation of a date and time by using the formatting rules of the current or a specified culture, trying to parse a string across different cultures can fail. To parse a specific date and time format across different locales, use one of the overloads of the method and provide a format specifier. ### Parsing and cultural conventions - All overloads of the method are culture-sensitive unless the string to be parsed conforms to the ISO 8601 pattern. The parsing operation uses the formatting information in a object that is derived as follows: + All overloads of the method are culture-sensitive unless the string to be parsed (which is represented by `s` in the following table) conforms to the ISO 8601 pattern. The parsing operation uses the formatting information in a object that is derived as follows: |If you call|And `provider` is|Formatting information is derived from| |-----------------|-----------------------|--------------------------------------------| @@ -4328,7 +4328,7 @@ The following example parses strings in each of these formats by using the forma ### Parsing and style elements - All overloads ignore leading, inner, or trailing white-space characters in `s`. The date and time can be bracketed with a pair of leading and trailing NUMBER SIGN characters ("#", U+0023), and can be trailed with one or more NULL characters (U+0000). + All overloads ignore leading, inner, or trailing white-space characters in the input string (which is represented by `s` in the following table). The date and time can be bracketed with a pair of leading and trailing NUMBER SIGN characters ("#", U+0023), and can be trailed with one or more NULL characters (U+0000). In addition, the overload has a `styles` parameter that consists of one or more members of the enumeration. This parameter defines how `s` should be interpreted and how the parse operation should convert `s` to a date and time. The following table describes the effect of each member on the parse operation. @@ -4375,8 +4375,7 @@ The `DateTime.Parse` overloads return a value whose [!NOTE] -> The C# examples in this article run in the [Try.NET](https://try.dot.net) inline code runner and playground. You can run an example in an interactive window by pressing the **Run** button. Once you execute the code, you can modify it and run the modified code by pressing **Run** again. The modified code either runs in the interactive window or, if compilation fails, the interactive window displays all C# compiler error messages. +[!INCLUDE[interactive-note](~/includes/csharp-interactive-note.md)] You can also download a complete set of `DateTime.Parse` examples, which are included in a [.NET Core 2.0 project for C#](~/samples/snippets/csharp/downloads/api/System/DateTime.Parse.zip) and a [.NET Core 2.0 project for Visual Basic](~/samples/snippets/visualbasic/downloads/api/System.DateTime.Parse.zip), from the [dotnet/docs GitHub repository](https://github.com/dotnet/docs). @@ -4558,7 +4557,7 @@ The following example parses an array of date strings by using the conventions o This method overload converts the date and time in `s` and sets the property of the returned value as follows: |If |Time zone conversion|Kind property| -|---------------------------|--------------------------| +|-----|-----|-----| |`s` contains no time zone information.|None.|| |`s` contains time zone information.|To the time in the local time zone|| |`s` contains time zone information, and `styles includes the flag.|To Coordinated Univeral Time (UTC)||