Class: DateTime

Namespace: System

Library: mscorlib.dll

It's an Structure, not really a Class. But this doesn't matter too much. It's like an static Class: you can use the name DateTime like the prefix/object.

We will see first the properties:

The special property used for the creation of an "object" is :

Now

It's used also for capture of the actual instant. The format is: MM/DD/YYYY hh:mm:ss

Example:

Some other properties:

DayOfWeek

Returns an int.The convention is: zero for Sunday, one for Monday etc.

DayOfYear

Hour

Millisecond

Minute

Month

Second

Ticks

Presents the quantity of 100-nanoseconds since 1/1/001 12:00:00

Year

The methods:

Add(someTimeSpan)

This method adds a TimeSpan to a DateTime. To define a TimeSpan we use:

TimeSpan ts = new TimeSpan(somedays,somehours,someminutes,someseconds);

AddDays(somedays)

AddHours(somehours)

AddMinutes(someminutes)

AddMiliseconds(somemiliseconds)

AddTicks(someticks)

AddYears(someyears)

Compare( someDateTime, someotherDateTime)

Returns what is the first date in time. The convention is:

 1 : the first one is the precedent;
         -1: the second one is the precedent;
         0 : same date.

Subtract(someTimeSpan)

Example:

ToUniversalTime()

Converts the value of the current DateTime to Coordinated Universal Time (UTC).


PREVIOUS LESSON NEXT LESSON
T.CONTENTS HOMEPAGE