Tuesday, May 4, 2021

C# Calendar class of current culture

using System;
using System.Globalization; // to use CultureInfo class
namespace ConsoleCultureInfo
{
    class Program
    {
        static void Main(string[] args)
        {
            //get current culture info and its properties
            CultureInfo currentCi = CultureInfo.CurrentCulture;
            Calendar clndr = currentCi.Calendar;
            Console.WriteLine("Year: {0}",clndr.GetYear(DateTime.Now));
            Console.WriteLine("Month: {0}",clndr.GetMonth(DateTime.Now));
            Console.WriteLine("Is Leap year: {0}",clndr.IsLeapYear(2021));
            Console.WriteLine("Three months later from the current month: {0}", clndr.AddMonths(DateTime.Now, 3));
            Console.ReadKey();
        }
    }
}

OUTPUT
Year: 2021
Month: 5
Is Leap year: False
Three months later from the current month: 2021-08-04 3:05:11 PM

No comments:

Post a Comment

Hot Topics