Find the date for the Chinese New Year

Problem:

You want to find the date of the Chinese new year for a given year.

Solution:

Use icu4j's Chinese calendar to perform the calculations.  You will specify a year in a Gregorian calendar and use that to set the time of the Chinese calendar.  Then set the calendar tot he first month and first day.

//Get a ULocale for Chinese written in simplified Chinese for China using a Chinese calendar
ULocale chinese = new ULocale("zh_Hans_CN@calendar=chinese");
//Get a Calendar instance specifying our ULocale.  This will give us a Chinese calendar
Calendar c = Calendar.getInstance(chinese);
//Get a Gregorian calendar instance
Calendar c2 = Calendar.getInstance();
//Set the year you want to find new Years for.  We will also set the month
//to half way through the year since the Chinese New Year won't occur until perhaps late February
c2.set(Calendar.YEAR, 2008);
c2.set(Calendar.MONTH, 5);
//Set the year of the Chinese Calendar
c.setTimeInMillis(c2.getTimeInMillis());
//Set the month to the first month.  Remember months are zero based
c.set(Calendar.MONTH, 0);
//Set the day to the first.  Remember dates are one based.
c.set(Calendar.DATE, 1);
//Output the date.  getTime() returns a Gregorian date.
System.out.println(c.getTime());

The output:

Thu Feb 07 22:35:16 EST 2008 Shows us the New Years occured on Feb 7th in 2008.  The time output is irrelevant.

 Discussion:

The length of the Chinese calendar's year varies from year to year.  Since the Calendar uses a leap month, the New Year can occur anywhere from late January to late February.