Programming Course in C# ¡Free!

12.01 - Date and time

 Saturday, April 06, 2013 published by Exercises C#
Create a program to display the current date and time with the following format:

Today is 6 of February of 2015. It´s 03:23:12.

using System;

class DateAndTime1
{
    static void Main( )
    {
        string day = DateTime.Now.Day.ToString("00");
        string month = GetMonth(DateTime.Now.Month); 
        int year = DateTime.Now.Year;
        string time = DateTime.Now.ToLongTimeString();

        Console.WriteLine("Today is {0} of {1} of {2}. It´s {3}.", day, month, year, time); 
    }

    static string GetMonth(int numberMonth) 
    {
        string[] months = 
            new string[] { "January", "February", "March", "April", "May", "June", "July", 
                           "August", "September", "October", "November", "Decenber" };

        return months[numberMonth - 1];
    }
}


using System;
using System.Globalization;

class DateAndTime2
{
    static void Main()
    {
        string day = DateTime.Now.Day.ToString("00");
        string month = DateTime.Now.ToString("MMM", CultureInfo.InvariantCulture);
        int year = DateTime.Now.Year;
        string time = DateTime.Now.ToLongTimeString();

        Console.WriteLine("Today is {0} of {1} of {2}. It´s {3}.", day, month, year, time);
    }
}