An answer: of course, the simplest way is you can parse that string into your fields and contruct new DateTime object then. But if the string is something like "12/8/2008 23:17", so how can you parse this string into month,day,year,hour and minute.
But .Net Framework already support you for such task. You can use DateTime.ParseExact() for this purpose. Here is sample code
1 DateTime convertedDateTime = DateTime.ParseExact(
2 "20/08/2008 13:10",
3 "MM/dd/yyyy HH:mm",
4 System.Globalization.CultureInfo.CurrentCulture);
5 Console.WriteLine(string.Format("Day: {0}", convertedDateTime.Day));
6 Console.WriteLine(string.Format("Month: {0}", convertedDateTime.Month));
7 Console.WriteLine(string.Format("Hour: {0}", convertedDateTime.Hour));
Hope this tip will help you
Powered by ScribeFire.