| |||||
DateTime.Parse MethodSystem Namespace DateTime Structure Converts the specified string representation of a date and time to its DateTime equivalent. Overload List1. 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. [ VB ] Overloads Public Shared Function Parse ( String, IFormatProvider, DateTimeStyles ) As DateTime
ExampleThe below code snippet demonstrates using the Parse method.
[ 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 |
| ||||
Check out related books at Amazon
© 2000-2008 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 aspxtreme