Convert DateTime to string using the specified format and culture-specific format information in CSharp
Description
The following code shows how to convert DateTime to string using the specified format and culture-specific format information.
Example
using System;/*from w w w . j a v a2s . c o m*/
using System.Globalization;
public class Example
{
public static void Main()
{
CultureInfo arSA = new CultureInfo("ar-SA");
arSA.DateTimeFormat.Calendar = new UmAlQuraCalendar();
DateTime date1 = new DateTime(1890, 9, 10);
try {
Console.WriteLine(date1.ToString("d", arSA));
}
catch (ArgumentOutOfRangeException) {
Console.WriteLine("{0:d} is earlier than {1:d} or later than {2:d}",
date1,
arSA.DateTimeFormat.Calendar.MinSupportedDateTime,
arSA.DateTimeFormat.Calendar.MaxSupportedDateTime);
}
}
}
The code above generates the following result.