Converts string to DateTimeOffset using the specified format, culture-specific format information, and style.
using System;
using System.Globalization;
public class Test
{
public static void Main()
{
string dateString, format;
DateTimeOffset result;
CultureInfo provider = CultureInfo.InvariantCulture;
// Parse date-only value with invariant culture and assume time is UTC.
dateString = "06/15/2008";
format = "d";
try
{
result = DateTimeOffset.ParseExact(dateString, format, provider,
DateTimeStyles.AssumeUniversal);
Console.WriteLine("'{0}' converts to {1}.", dateString, result.ToString());
}
catch (FormatException)
{
Console.WriteLine("'{0}' is not in the correct format.", dateString);
}
}
}
Related examples in the same category