Best Industrial Training in C,C++,PHP,Dot Net,Java in Jalandhar

Wednesday 26 December 2012

DateTime(Value Type)

DateTime

The DateTime is value type. It represents an instant in time, typically expressed as a date and time of day.
using System;

class CSharpApp
{
    static void Main()
    {
        DateTime today;

        today = DateTime.Now;

        System.Console.WriteLine(today);
        System.Console.WriteLine(today.ToShortDateString());
        System.Console.WriteLine(today.ToShortTimeString());               

    }
}
We show today's date in three different formats. Date & time, date and time.
DateTime today;
We declare a variable of DateTime data type.
today = DateTime.Now;
Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.
System.Console.WriteLine(today);
This line prints the date in full format.
System.Console.WriteLine(today.ToShortDateString());
System.Console.WriteLine(today.ToShortTimeString());
The ToShortDateString() returns a short date string format, the ToShortTimeString() returns a short time string format.
$ ./date.exe 
10/15/2010 10:56:37 AM
10/15/2010
10:56 AM

No comments:

Post a Comment