asp.net.ph

DateTime Constructor ( Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar )

System Namespace   DateTime Structure


Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, second, and millisecond for the specified Calendar.

[ VB ]
<Serializable>
Public Sub New ( _
   ByVal year As Integer, _
   ByVal month As Integer, _
   ByVal day As Integer, _
   ByVal hour As Integer, _
   ByVal minute As Integer, _
   ByVal second As Integer, _
   ByVal millisecond As Integer, _
   ByVal calendar As Calendar _
)

[ C# ]
[ Serializable ]
public DateTime (
   int year,
   int month,
   int day,
   int hour,
   int minute,
   int second,
   int millisecond,
   Calendar calendar
);

[ C++ ]
[ Serializable ]
public: DateTime (
   int year,
   int month,
   int day,
   int hour,
   int minute,
   int second,
   int millisecond,
   Calendar* calendar
);

[ JScript ]
public Serializable
function DateTime (
   year : int,
   month : int,
   day : int,
   hour : int,
   minute : int,
   second : int,
   millisecond : int,
   calendar : Calendar
);

Parameters

year
The year ( 1 through 9999 ).
month
The month ( 1 through the number of months in calendar ).
day
The day ( 1 through the number of days in month ).
hour
The hours ( 0 through 23 ).
minute
The minutes ( 0 through 59 ).
second
The seconds ( 0 through 59 ).
millisecond
The milliseconds.
calendar
The Calendar that applies to this DateTime.

Exceptions


Exception Type Condition
ArgumentNullException calendar is a null reference ( Nothing in Visual Basic ).
ArgumentOutOfRangeException year is less than 1 or greater than 9999.

-or-

month is less than 1 or greater than the number of months in calendar.

-or-

day is less than 1 or greater than the number of days in month.

-or-

hour is less than 0 or greater than 23.

-or-

minute is less than 0 or greater than 59.

-or-

second is less than 0 or greater than 59.

ArgumentException Specified parameters evaluate to less than MinValue or more than MaxValue.

Remarks

The allowable values for year, month, and day depend on the specified Calendar. An exception is thrown if the specified date and time cannot be expressed using calendar.

The System.Globalization namespace provides several calendars including GregorianCalendar and JulianCalendar.

Example

The following demonstrates using this constructor.

// create a new instance of DateTime containing the date
// 7/28/1979 at 10:35:05 PM using the en-US calendar.
System.Globalization.CultureInfo info =
   new System.Globalization.CultureInfo ( "en-US", false );

System.Globalization.Calendar calendar = info.Calendar;

System.DateTime dateTime =
   new System.DateTime ( 1979,      // Year
                  07,         // Month
                  28,         // Day
                  22,         // Hour
                  35,         // Minute
                  5,         // Second
                  15,         // Millisecond
                  calendar   // calendar
                   );

// Write the DateTime as "Saturday, July 28, 1979 10:35:05 PM".
System.Response.WriteLine ( "{ 0:F }", dateTime );
  C# VB

See Also

DateTime Members   DateTime Constructor Overload List   Int32   Calendar Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph