This method throws an
ArgumentOutOfRangeException when using the
JapaneseCalendar to format a date that occurs before September 8th, 1868.
The following method attempts to call
DateTime.ToString(IFormatProvider) on a
DateTime instance with the value September 7th, 1868.
[C#]
using System;
using System.Globalization;
namespace Samples
{
class Program
{
static void Main(string[] args)
{
CultureInfo culture = new CultureInfo("ja-JP");
culture.DateTimeFormat.Calendar = new JapaneseCalendar();
DateTime date = new DateTime(1868, 9, 7);
try
{
date.ToString(culture);
}
catch (ArgumentOutOfRangeException ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
The above outputs the following:
Specified time is not supported in this calendar. It should be between 09/08/186
8 00:00:00 (Gregorian date) and 12/31/9999 23:59:59 (Gregorian date), inclusive.
Parameter name: time
This can also occur without explicitly specifying the
JapaneseCalendar when the current user's calender is set to the Wareki calendar in Regional and Language Options. To set the calendar to this, do the following in Windows Vista and Windows Server 2003:
- Choose Start -> Control Panel -> Regional and Language Options
- From the Current format drop down, choose Japanese (Japan)
- Click Customize this format and select the Date tab
- Under Calendar type, choose 和暦
- Click OK and then OK again
The following method attempts to call DateTime.ToString() on a DateTime instance with the value September 7th, 1868. This code sample expects the above steps to have been done.
[C#]
using System;
using System.Globalization;
namespace Samples
{
class Program
{
static void Main(string[] args)
{
DateTime date = new DateTime(1868, 9, 7);
try
{
date.ToString();
}
catch (ArgumentOutOfRangeException ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
The above outputs the following:
Specified time is not supported in this calendar. It should be between 09/08/186
8 00:00:00 (Gregorian date) and 12/31/9999 23:59:59 (Gregorian date), inclusive.
Parameter name: time