C# DateTime DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar)
Description
DateTime DateTime(Int32, Int32, Int32, Int32, Int32, Int32,
Int32, Calendar)
initializes a new instance of the DateTime structure
to the specified year, month, day, hour, minute, second, and millisecond
for the specified calendar.
Syntax
DateTime.DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar)
has the following syntax.
public DateTime(/* ww w . j a va 2s. co m*/
int year,
int month,
int day,
int hour,
int minute,
int second,
int millisecond,
Calendar calendar
)
Parameters
DateTime.DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar)
has the following parameters.
year
- The year (1 through the number of years in calendar).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 (0 through 999).calendar
- The calendar that is used to interpret year, month, and day.
Example
The following example calls the DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar) constructor twice to instantiate two DateTime values.
using System;/*from ww w . java 2 s . c o m*/
using System.Globalization;
using System.Text.RegularExpressions;
using System.Threading;
public class Example
{
public static void Main()
{
PersianCalendar persian = new PersianCalendar();
DateTime date1 = new DateTime(1389, 5, 27, 16, 32, 18, 500, persian);
Console.WriteLine(date1.ToString("M/dd/yyyy h:mm:ss.fff tt"));
Console.WriteLine("{0}/{1}/{2} {3}{7}{4:D2}{7}{5:D2}.{6:G3}\n",
persian.GetMonth(date1),
persian.GetDayOfMonth(date1),
persian.GetYear(date1),
persian.GetHour(date1),
persian.GetMinute(date1),
persian.GetSecond(date1),
persian.GetMilliseconds(date1),
DateTimeFormatInfo.CurrentInfo.TimeSeparator);
}
}
The code above generates the following result.