Convert DateTimeOffset to string with different culture information
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
CultureInfo[] cultures = new CultureInfo[] {CultureInfo.InvariantCulture,
new CultureInfo("en-us"),
new CultureInfo("fr-fr"),
new CultureInfo("de-DE"),
new CultureInfo("es-ES")};
DateTimeOffset thisDate = new DateTimeOffset(2010, 5, 1, 9, 0, 0, TimeSpan.Zero);
foreach (CultureInfo culture in cultures)
{
string cultureName;
if (string.IsNullOrEmpty(culture.Name))
cultureName = culture.NativeName;
else
cultureName = culture.Name;
Console.WriteLine("In {0}, {1}", cultureName, thisDate.ToString(culture));
}
}
}
Related examples in the same category