asp.net.ph

DateTime.Parse Method

System Namespace   DateTime Structure


Converts the specified string representation of a date and time to its DateTime equivalent.

Overload List

1. Converts the specified string representation of a date and time to its DateTime equivalent.

2. Converts the specified string representation of a date and time to its DateTime equivalent using the specified culture-specific format information.

3. Converts the specified string representation of a date and time to its DateTime equivalent using the specified culture-specific format information and formatting style.


Example

The below code snippet demonstrates using the Parse method.

NOTE: This example shows how to use one of the overloaded versions of Parse. For other examples that might be available, see the individual overload topics.

[ VB ]
Dim strMyDateTime As String
strMyDateTime = "2/16/1992 12:15:12"

' myDateTime gets Feburary 16, 1992, 12 hours, 15 min and 12 sec.
Dim myDateTime As System.DateTime
myDateTime = System.DateTime.Parse ( strMyDateTime )

Dim format As New System.Globalization.CultureInfo ( "fr-FR", True )

' Reverse month and day to conform to a different format.
Dim strMyDateTimeFrench As String
strMyDateTimeFrench = "    16/02/1992 12:15:12"

' myDateTimeFrench gets Feburary 16, 1992, 12 hours,
' 15 min and 12 sec.
Dim myDateTimeFrench As System.DateTime
myDateTimeFrench = System.DateTime.Parse ( _
                           strMyDateTimeFrench, _
                           format, _
                           System.Globalization. _
                              DateTimeStyles.NoCurrentDateDefault )

Dim expectedFormats As String ( ) = { "G", "g", "f", "F" }
' myDateTimeFrench gets Feburary 16, 1992, 12 hours,
' 15 min and 12 sec.
myDateTimeFrench = System.DateTime.ParseExact ( _
                              strMyDateTimeFrench, _
                              expectedFormats, _
                              format, _
                              System.Globalization. _
                                 DateTimeStyles.AllowWhiteSpaces )

[ C# ]
string strMyDateTime = "2/16/1992 12:15:12";

// myDateTime gets Feburary 16, 1992, 12 hours, 15 min and 12 sec.
System.DateTime myDateTime =
   System.DateTime.Parse ( strMyDateTime );

System.IFormatProvider format =
   new System.Globalization.CultureInfo ( "fr-FR", true );

// Reverse month and day to conform to a different format.
string strMyDateTimeFrench = "    16/02/1992 12:15:12";

// myDateTimeFrench gets Feburary 16, 1992, 12 hours,
// 15 min and 12 sec.
System.DateTime myDateTimeFrench =
   System.DateTime.Parse ( strMyDateTimeFrench,
                    format,
                    System.Globalization.
                     DateTimeStyles.NoCurrentDateDefault );

string [ ] expectedFormats = { "G", "g", "f" ,"F" };
// myDateTimeFrench gets Feburary 16, 1992, 12 hours,
// 15 min and 12 sec.
myDateTimeFrench =
   System.DateTime.ParseExact ( strMyDateTimeFrench,
                        expectedFormats,
                        format,
                        System.Globalization.
                        DateTimeStyles.AllowWhiteSpaces );
See Also

DateTime Members Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph