Monday, March 10, 2008

C# and Calendars

C# provides abstract class Calendar, which implements basic calendar operations, and different calendar implementations:

GregorianCalendar, HebrewCalendar, HijriCalendar, JapaneseCalendar, JulianCalendar, KoreanCalendar, TaiwanCalendar, and ThaiBuddhistCalendar.

Sample of calendars usage:

using System;
using System.Globalization;

namespace CalendarSamples
{
class Program
{
static void Main()
{
DateTime now = DateTime.Now;

HebrewCalendar hebrewCalendar = new HebrewCalendar();
String hebrewDate = String.Format("{0} {1} {2}",
hebrewCalendar.GetDayOfMonth(now),
hebrewCalendar.GetMonth(now),
hebrewCalendar.GetYear(now));

GregorianCalendar gregorianCalendar = new GregorianCalendar();
String gregorianDate = String.Format("{0} {1} {2}",
gregorianCalendar.GetDayOfMonth(now),
gregorianCalendar.GetMonth(now),
gregorianCalendar.GetYear(now));

JulianCalendar julianCalendar = new JulianCalendar();
String julianCDate = String.Format("{0} {1} {2}",
julianCalendar.GetDayOfMonth(now),
julianCalendar.GetMonth(now),
julianCalendar.GetYear(now));

Console.WriteLine("date: " + now);
Console.WriteLine("hebrew date: " + hebrewDate);
Console.WriteLine("gregorianCalendar date: " + gregorianDate);
Console.WriteLine("julianCalendar date: " + julianCDate);
}
}
}





Additional Links:

1 comment:

Anonymous said...

The C# Calendar Control provides many features, like months preview, multi-month view, date zooming, multi-day selection, globalization support and data binding.