Mega Code Archive

 
Categories / C# / Date Time
 

Converts DateTimeOffset to string using the specified format

using System; using System.Globalization; using System.Threading; public class Example {    public static void Main()    {       DateTimeOffset date1 = new DateTimeOffset(new DateTime(2010, 7, 21),                                                 TimeSpan.Zero);       CultureInfo heIL = new CultureInfo("he-IL");       heIL.DateTimeFormat.Calendar = new HebrewCalendar();       // Change current culture to he-IL.       Thread.CurrentThread.CurrentCulture = heIL;       Console.WriteLine(date1.ToString("G"));    } }