Mega Code Archive

 
Categories / C# / Date Time
 

Converts DateTimeOffset to string using the specified culture-specific formatting information

using System; using System.Globalization; public class Example {    public static void Main()    {       CultureInfo jaJP = new CultureInfo("ja-JP");       jaJP.DateTimeFormat.Calendar = new JapaneseCalendar();        DateTimeOffset date1 = new DateTimeOffset(new DateTime(2010, 1, 1),TimeSpan.Zero);       try {          Console.WriteLine(date1.ToString(jaJP));       }       catch (ArgumentOutOfRangeException) {          Console.WriteLine("{0:d} is earlier than {1:d} or later than {2:d}", date1,                             jaJP.DateTimeFormat.Calendar.MinSupportedDateTime, jaJP.DateTimeFormat.Calendar.MaxSupportedDateTime);        }    } }