Add to year, month, week, day, hour, minute, second and millisecton
using System;
using System.Globalization;
public class MainClass{
public static void Main() {
DateTime myDT = new DateTime( 2010, 4, 13, new GregorianCalendar() );
Calendar myCal = CultureInfo.InvariantCulture.Calendar;
myDT = myCal.AddYears( myDT, 5 );
myDT = myCal.AddMonths( myDT, 5 );
myDT = myCal.AddWeeks( myDT, 5 );
myDT = myCal.AddDays( myDT, 5 );
myDT = myCal.AddHours( myDT, 5 );
myDT = myCal.AddMinutes( myDT, 5 );
myDT = myCal.AddSeconds( myDT, 5 );
myDT = myCal.AddMilliseconds( myDT, 5 );
DisplayValues( myCal, myDT );
}
public static void DisplayValues( Calendar myCal, DateTime myDT ) {
Console.WriteLine( "Era: {0}", myCal.GetEra( myDT ) );
Console.WriteLine( "Year: {0}", myCal.GetYear( myDT ) );
Console.WriteLine( "Month: {0}", myCal.GetMonth( myDT ) );
Console.WriteLine( "DayOfYear: {0}", myCal.GetDayOfYear( myDT ) );
Console.WriteLine( "DayOfMonth: {0}", myCal.GetDayOfMonth( myDT ) );
Console.WriteLine( "DayOfWeek: {0}", myCal.GetDayOfWeek( myDT ) );
Console.WriteLine( "Hour: {0}", myCal.GetHour( myDT ) );
Console.WriteLine( "Minute: {0}", myCal.GetMinute( myDT ) );
Console.WriteLine( "Second: {0}", myCal.GetSecond( myDT ) );
Console.WriteLine( "Milliseconds: {0}", myCal.GetMilliseconds( myDT ) );
}
}
Related examples in the same category