DateTime 생성자

정의

DateTime 구조체의 새 인스턴스를 초기화합니다.

오버로드

DateTime(Int64)

DateTime 구조체의 새 인스턴스를 지정된 틱 수로 초기화합니다.

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

DateTime 구조체의 새 인스턴스를 지정된 달력의 지정된 연도, 월, 일, 시, 분, 초, 밀리초 및 UTC(협정 세계시) 또는 현지 시간으로 초기화합니다.

DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind)

DateTime 구조체의 새 인스턴스를 지정된 달력의 지정된 연도, 월, 일, 시, 분, 초, 밀리초 및 UTC(협정 세계시) 또는 현지 시간으로 초기화합니다.

DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, DateTimeKind)

DateTime 구조체의 새 인스턴스를 지정된 달력의 지정된 연도, 월, 일, 시, 분, 초, 밀리초 및 UTC(협정 세계시) 또는 현지 시간으로 초기화합니다.

DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)

DateTime 구조체의 새 인스턴스를 지정된 달력의 지정된 연도, 월, 일, 시, 분, 초, 밀리초 및 UTC(협정 세계시) 또는 현지 시간으로 초기화합니다.

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

DateTime 구조체의 새 인스턴스를 지정된 달력에서 지정된 연도, 월, 일, 시, 분, 초 및 밀리초로 초기화합니다.

DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind)

DateTime 구조체의 새 인스턴스를 지정된 연도, 월, 일, 시, 분, 초, 밀리초 및 UTC(협정 세계시) 또는 현지 시간으로 초기화합니다.

DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32)

DateTime 구조체의 새 인스턴스를 지정된 연도, 월, 일, 시, 분, 초 및 밀리초로 초기화합니다.

DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, DateTimeKind)

DateTime 구조체의 새 인스턴스를 지정된 달력의 지정된 연도, 월, 일, 시, 분, 초, 밀리초 및 UTC(협정 세계시) 또는 현지 시간으로 초기화합니다.

DateTime(Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind)

DateTime 구조체의 새 인스턴스를 지정된 연도, 월, 일, 시, 분, 초 및 UTC(협정 세계시) 또는 현지 시간으로 초기화합니다.

DateTime(Int32, Int32, Int32, Int32, Int32, Int32)

DateTime 구조체의 새 인스턴스를 지정된 연도, 월, 날짜, 시, 분 및 초로 초기화합니다.

DateTime(Int32, Int32, Int32, Calendar)

DateTime 구조체의 새 인스턴스를 지정된 달력의 지정된 연도, 월 및 날짜로 초기화합니다.

DateTime(Int32, Int32, Int32)

DateTime 구조체의 새 인스턴스를 특정 연도, 월 및 날짜로 초기화합니다.

DateTime(DateOnly, TimeOnly, DateTimeKind)

지정된 및 에 대한 구조체의 DateTime 새 instance 초기화하고 TimeOnly 지정된 DateTimeKind를 준수 DateOnly 합니다.

DateTime(Int64, DateTimeKind)

DateTime 구조체의 새 인스턴스를 지정된 틱 수 및 UTC(협정 세계시) 또는 현지 시간으로 초기화합니다.

DateTime(DateOnly, TimeOnly)

구조체의 새 instance DateTime 지정된 DateOnlyTimeOnly로 초기화합니다. 새 instance 종류가 Unspecified 있습니다.

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

DateTime 구조체의 새 인스턴스를 지정된 달력에서 지정된 연도, 월, 일, 시, 분 및 초로 초기화합니다.

DateTime(Int64)

DateTime 구조체의 새 인스턴스를 지정된 틱 수로 초기화합니다.

public:
 DateTime(long ticks);
public DateTime (long ticks);
new DateTime : int64 -> DateTime
Public Sub New (ticks As Long)

매개 변수

ticks
Int64

그레고리오력에서 0001년 1월 1일 00:00:00.000부터 경과한 100나노초 간격의 수로 표현한 날짜와 시간입니다.

예외

예제

다음 예제에서는 생성자 중 DateTime 하나를 보여 줍니다.

// This example demonstrates the DateTime(Int64) constructor.
using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Instead of using the implicit, default "G" date and time format string, we 
   // use a custom format string that aligns the results and inserts leading zeroes.
   String^ format = "{0}) The {1} date and time is {2:MM/dd/yyyy hh:mm:ss tt}";
   
   // Create a DateTime for the maximum date and time using ticks.
   DateTime dt1 = DateTime(DateTime::MaxValue.Ticks);
   
   // Create a DateTime for the minimum date and time using ticks.
   DateTime dt2 = DateTime(DateTime::MinValue.Ticks);
   
   // Create a custom DateTime for 7/28/1979 at 10:35:05 PM using a 
   // calendar based on the "en-US" culture, and ticks. 
   Int64 ticks = DateTime(1979,07,28,22,35,5,(gcnew CultureInfo( "en-US",false ))->Calendar).Ticks;
   DateTime dt3 = DateTime(ticks);
   Console::WriteLine( format, 1, "maximum", dt1 );
   Console::WriteLine( format, 2, "minimum", dt2 );
   Console::WriteLine( format, 3, "custom ", dt3 );
   Console::WriteLine( "\nThe custom date and time is created from {0:N0} ticks.", ticks );
}

/*
This example produces the following results:

1) The maximum date and time is 12/31/9999 11:59:59 PM
2) The minimum date and time is 01/01/0001 12:00:00 AM
3) The custom  date and time is 07/28/1979 10:35:05 PM

The custom date and time is created from 624,376,461,050,000,000 ticks.

*/
// This example demonstrates the DateTime(Int64) constructor.
open System
open System.Globalization

// Create a DateTime for the maximum date and time using ticks.
let dt1 = DateTime DateTime.MaxValue.Ticks

// Create a DateTime for the minimum date and time using ticks.
let dt2 = DateTime DateTime.MinValue.Ticks

// Create a custom DateTime for 7/28/1979 at 10:35:05 PM using a
// calendar based on the "en-US" culture, and ticks.
let ticks = DateTime(1979, 07, 28, 22, 35, 5, CultureInfo("en-US", false).Calendar).Ticks
let dt3 = DateTime ticks

printfn $"""1) The maximum date and time is {dt1.ToString "MM-dd/yyyy hh:mm:ss tt"}"""
printfn $"""2) The minimum date and time is {dt2.ToString "MM/dd/yyyy hh:mm:ss tt"}"""
printfn $"""3) The custom  date and time is {dt3.ToString "MM/dd/yyyy hh:mm:ss tt"}"""

printfn $"\nThe custom date and time is created from {ticks:N0} ticks."

// This example produces the following results:
//
// 1) The maximum date and time is 12/31/9999 11:59:59 PM
// 2) The minimum date and time is 01/01/0001 12:00:00 AM
// 3) The custom  date and time is 07/28/1979 10:35:05 PM
//
// The custom date and time is created from 624,376,461,050,000,000 ticks.
// This example demonstrates the DateTime(Int64) constructor.
using System;
using System.Globalization;

class Sample
{
    public static void Main()
    {
// Instead of using the implicit, default "G" date and time format string, we
// use a custom format string that aligns the results and inserts leading zeroes.
    string format = "{0}) The {1} date and time is {2:MM/dd/yyyy hh:mm:ss tt}";

// Create a DateTime for the maximum date and time using ticks.
    DateTime dt1 = new DateTime(DateTime.MaxValue.Ticks);

// Create a DateTime for the minimum date and time using ticks.
    DateTime dt2 = new DateTime(DateTime.MinValue.Ticks);

// Create a custom DateTime for 7/28/1979 at 10:35:05 PM using a
// calendar based on the "en-US" culture, and ticks.
    long ticks = new DateTime(1979, 07, 28, 22, 35, 5,
    new CultureInfo("en-US", false).Calendar).Ticks;
    DateTime dt3 = new DateTime(ticks);

    Console.WriteLine(format, 1, "maximum", dt1);
    Console.WriteLine(format, 2, "minimum", dt2);
    Console.WriteLine(format, 3, "custom ", dt3);
    Console.WriteLine("\nThe custom date and time is created from {0:N0} ticks.", ticks);
    }
}
/*
This example produces the following results:

1) The maximum date and time is 12/31/9999 11:59:59 PM
2) The minimum date and time is 01/01/0001 12:00:00 AM
3) The custom  date and time is 07/28/1979 10:35:05 PM

The custom date and time is created from 624,376,461,050,000,000 ticks.

*/
' This example demonstrates the DateTime(Int64) constructor.
Imports System.Globalization

Class Sample
   Public Shared Sub Main()
      ' Instead of using the implicit, default "G" date and time format string, we 
      ' use a custom format string that aligns the results and inserts leading zeroes.
      Dim format As String = "{0}) The {1} date and time is {2:MM/dd/yyyy hh:mm:ss tt}"
      
      ' Create a DateTime for the maximum date and time using ticks.
      Dim dt1 As New DateTime(DateTime.MaxValue.Ticks)
      
      ' Create a DateTime for the minimum date and time using ticks.
      Dim dt2 As New DateTime(DateTime.MinValue.Ticks)
      
      ' Create a custom DateTime for 7/28/1979 at 10:35:05 PM using a 
      ' calendar based on the "en-US" culture, and ticks. 
      Dim ticks As Long = New DateTime(1979, 7, 28, 22, 35, 5, _
                                       New CultureInfo("en-US", False).Calendar).Ticks
      Dim dt3 As New DateTime(ticks)
      
      Console.WriteLine(format, 1, "maximum", dt1)
      Console.WriteLine(format, 2, "minimum", dt2)
      Console.WriteLine(format, 3, "custom ", dt3)
      Console.WriteLine(vbCrLf & "The custom date and time is created from {0:N0} ticks.", ticks)
   End Sub
End Class
'
'This example produces the following results:
'
'1) The maximum date and time is 12/31/9999 11:59:59 PM
'2) The minimum date and time is 01/01/0001 12:00:00 AM
'3) The custom  date and time is 07/28/1979 10:35:05 PM
'
'The custom date and time is created from 624,376,461,050,000,000 ticks.
'

설명

Kind 속성이 Unspecified으로 초기화됩니다.

날짜 및 시간 데이터 또는 제한 된 수준의 표준 시간대는 이식성 인식의 중요 한 애플리케이션을 사용할 수 있습니다 해당 DateTimeOffset 생성자입니다.

적용 대상

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

DateTime 구조체의 새 인스턴스를 지정된 달력의 지정된 연도, 월, 일, 시, 분, 초, 밀리초 및 UTC(협정 세계시) 또는 현지 시간으로 초기화합니다.

public:
 DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond, System::Globalization::Calendar ^ calendar);
public DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond, System.Globalization.Calendar calendar);
new DateTime : int * int * int * int * int * int * int * int * System.Globalization.Calendar -> DateTime
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, millisecond As Integer, microsecond As Integer, calendar As Calendar)

매개 변수

year
Int32

연도(1부터 calendar에 있는 연수까지)

month
Int32

월(1부터 calendar에 있는 월수까지)

day
Int32

일(1부터 month에 있는 일수까지)

hour
Int32

시(0부터 23까지)

minute
Int32

분(0부터 59까지)

second
Int32

초(0부터 59까지)

millisecond
Int32

밀리초(0부터 999까지)

microsecond
Int32

마이크로초(0~999)입니다.

calendar
Calendar

year, monthday를 해석하는 데 사용되는 달력입니다.

예외

calendarnull입니다.

yearcalendar에서 지원되는 범위에 없습니다.

또는

month가 1보다 작거나 calendar의 개월 수보다 큽니다.

또는

day 가 1보다 작거나 month의 일 수보다 큽니다.

또는

hour가 0보다 작거나 23보다 큽니다.

또는

minute가 0보다 작거나 59보다 큽니다.

또는

second가 0보다 작거나 59보다 큽니다.

또는

millisecond가 0보다 작거나 999보다 큽니다.

또는

microsecond가 0보다 작거나 999보다 큽니다.

설명

, monthday 매개 변수에 허용되는 year값은 매개 변수에 calendar 따라 달라집니다. 를 사용하여 calendar지정된 날짜와 시간을 표현할 수 없는 경우 예외가 throw됩니다.

날짜 및 시간 데이터 또는 제한 된 수준의 표준 시간대는 이식성 인식의 중요 한 애플리케이션을 사용할 수 있습니다 해당 DateTimeOffset 생성자입니다.

적용 대상

DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind)

DateTime 구조체의 새 인스턴스를 지정된 달력의 지정된 연도, 월, 일, 시, 분, 초, 밀리초 및 UTC(협정 세계시) 또는 현지 시간으로 초기화합니다.

public:
 DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond, DateTimeKind kind);
public DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond, DateTimeKind kind);
new DateTime : int * int * int * int * int * int * int * int * DateTimeKind -> DateTime
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, millisecond As Integer, microsecond As Integer, kind As DateTimeKind)

매개 변수

year
Int32

연도(1부터 9999까지)

month
Int32

월(1부터 12까지)

day
Int32

일(1부터 month에 있는 일수까지)

hour
Int32

시(0부터 23까지)

minute
Int32

분(0부터 59까지)

second
Int32

초(0부터 59까지)

millisecond
Int32

밀리초(0부터 999까지)

microsecond
Int32

마이크로초(0~999)입니다.

kind
DateTimeKind

year, month, day, hour, minute, secondmillisecond가 현지 시간 또는 UTC(협정 세계시)를 지정하는지, 아니면 둘 다 지정하지 않는지를 나타내는 열거형 값 중 하나입니다.

예외

year가 1보다 작거나 9999보다 큽니다.

또는

month가 1보다 작거나 12보다 큽니다.

또는

day 가 1보다 작거나 month의 일 수보다 큽니다.

또는

hour가 0보다 작거나 23보다 큽니다.

또는

minute가 0보다 작거나 59보다 큽니다.

또는

second가 0보다 작거나 59보다 큽니다.

또는

millisecond가 0보다 작거나 999보다 큽니다.

또는

microsecond가 0보다 작거나 999보다 큽니다.

kindDateTimeKind 값 중 하나가 아닙니다.

설명

이 생성자는 및 를 yearmonthday 그레고리오력의 1년, 월 및 일로 해석합니다. 다른 달력에서 DateTime 연도, 월 및 일을 사용하여 값을 인스턴스화하려면 생성자를 호출합니다 DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, DateTimeKind) .

날짜 및 시간 데이터 또는 제한 된 수준의 표준 시간대는 이식성 인식의 중요 한 애플리케이션을 사용할 수 있습니다 해당 DateTimeOffset 생성자입니다.

적용 대상

DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, DateTimeKind)

DateTime 구조체의 새 인스턴스를 지정된 달력의 지정된 연도, 월, 일, 시, 분, 초, 밀리초 및 UTC(협정 세계시) 또는 현지 시간으로 초기화합니다.

public:
 DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, System::Globalization::Calendar ^ calendar, DateTimeKind kind);
public DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond, System.Globalization.Calendar calendar, DateTimeKind kind);
new DateTime : int * int * int * int * int * int * int * System.Globalization.Calendar * DateTimeKind -> DateTime
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, millisecond As Integer, calendar As Calendar, kind As DateTimeKind)

매개 변수

year
Int32

연도(1부터 calendar에 있는 연수까지)

month
Int32

월(1부터 calendar에 있는 월수까지)

day
Int32

일(1부터 month에 있는 일수까지)

hour
Int32

시(0부터 23까지)

minute
Int32

분(0부터 59까지)

second
Int32

초(0부터 59까지)

millisecond
Int32

밀리초(0부터 999까지)

calendar
Calendar

year, monthday를 해석하는 데 사용되는 달력입니다.

kind
DateTimeKind

year, month, day, hour, minute, secondmillisecond가 현지 시간 또는 UTC(협정 세계시)를 지정하는지, 아니면 둘 다 지정하지 않는지를 나타내는 열거형 값 중 하나입니다.

예외

calendar이(가) null인 경우

yearcalendar에서 지원되는 범위에 없습니다.

또는

month가 1보다 작거나 calendar의 개월 수보다 큽니다.

또는

day 가 1보다 작거나 month의 일 수보다 큽니다.

또는

hour가 0보다 작거나 23보다 큽니다.

또는

minute가 0보다 작거나 59보다 큽니다.

또는

second가 0보다 작거나 59보다 큽니다.

또는

millisecond가 0보다 작거나 999보다 큽니다.

kindDateTimeKind 값 중 하나가 아닙니다.

예제

다음 예제에서는 생성자를 두 번 호출 DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, DateTimeKind) 하여 두 DateTime 값을 인스턴스화합니다. 첫 번째 호출은 개체를 DateTime 사용하여 PersianCalendar 값을 인스턴스화합니다. 페르시아 달력은 문화권의 기본 달력으로 지정할 수 없으므로 페르시아 달력에 날짜를 표시하려면 , PersianCalendar.GetDayOfMonthPersianCalendar.GetYear 메서드에 대한 개별 호출이 PersianCalendar.GetMonth필요합니다. 생성자에 대한 두 번째 호출은 개체를 DateTime 사용하여 HijriCalendar 값을 인스턴스화합니다. 이 예제에서는 현재 문화권을 아랍어(시리아)로 변경하고 현재 문화권의 기본 달력을 Hijri 달력으로 변경합니다. Hijri는 현재 문화권의 기본 달력이므로 메서드는 Console.WriteLine 이를 사용하여 날짜의 서식을 지정합니다. 이전 현재 문화권(이 경우 영어(미국))이 복원되면 Console.WriteLine 메서드는 현재 문화권의 기본 그레고리오력 을 사용하여 날짜 서식을 지정합니다.

using System;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Threading;

public class Example
{
   public static void Main()
   {
      Console.WriteLine("Using the Persian Calendar:");
      PersianCalendar persian = new PersianCalendar();
      DateTime date1 = new DateTime(1389, 5, 27, 16, 32, 18, 500,
                                    persian, DateTimeKind.Local);
      Console.WriteLine("{0:M/dd/yyyy h:mm:ss.fff tt} {1}", date1, date1.Kind);
      Console.WriteLine("{0}/{1}/{2} {3}{8}{4:D2}{8}{5:D2}.{6:G3} {7}\n",
                                       persian.GetMonth(date1),
                                       persian.GetDayOfMonth(date1),
                                       persian.GetYear(date1),
                                       persian.GetHour(date1),
                                       persian.GetMinute(date1),
                                       persian.GetSecond(date1),
                                       persian.GetMilliseconds(date1),
                                       date1.Kind,
                                       DateTimeFormatInfo.CurrentInfo.TimeSeparator);

      Console.WriteLine("Using the Hijri Calendar:");
      // Get current culture so it can later be restored.
      CultureInfo dftCulture = Thread.CurrentThread.CurrentCulture;

      // Define strings for use in composite formatting.
      string dFormat;
      string fmtString;
      // Define Hijri calendar.
      HijriCalendar hijri = new HijriCalendar();
      // Make ar-SY the current culture and Hijri the current calendar.
      Thread.CurrentThread.CurrentCulture = new CultureInfo("ar-SY");
      CultureInfo current = CultureInfo.CurrentCulture;
      current.DateTimeFormat.Calendar = hijri;
      dFormat = current.DateTimeFormat.ShortDatePattern;
      // Ensure year is displayed as four digits.
      dFormat = Regex.Replace(dFormat, "/yy$", "/yyyy") + " H:mm:ss.fff";
      fmtString = "{0} culture using the {1} calendar: {2:" + dFormat + "} {3}";
      DateTime date2 = new DateTime(1431, 9, 9, 16, 32, 18, 500,
                                    hijri, DateTimeKind.Local);
      Console.WriteLine(fmtString, current, GetCalendarName(hijri),
                        date2, date2.Kind);

      // Restore previous culture.
      Thread.CurrentThread.CurrentCulture = dftCulture;
      dFormat = DateTimeFormatInfo.CurrentInfo.ShortDatePattern +" H:mm:ss.fff";
      fmtString = "{0} culture using the {1} calendar: {2:" + dFormat + "} {3}";
      Console.WriteLine(fmtString,
                        CultureInfo.CurrentCulture,
                        GetCalendarName(CultureInfo.CurrentCulture.Calendar),
                        date2, date2.Kind);
   }

   private static string GetCalendarName(Calendar cal)
   {
      return Regex.Match(cal.ToString(), "\\.(\\w+)Calendar").Groups[1].Value;
   }
}
// The example displays the following output:
//    Using the Persian Calendar:
//    8/18/2010 4:32:18.500 PM Local
//    5/27/1389 16:32:18.500 Local
//
//    Using the Hijri Calendar:
//    ar-SY culture using the Hijri calendar: 09/09/1431 16:32:18.500 Local
//    en-US culture using the Gregorian calendar: 8/18/2010 16:32:18.500 Local
open System
open System.Globalization
open System.Text.RegularExpressions
open System.Threading

let getCalendarName (cal: Calendar) =
      Regex.Match(string cal, "\\.(\\w+)Calendar").Groups[1].Value

printfn "Using the Persian Calendar:"
let persian = PersianCalendar()
let date1 = DateTime(1389, 5, 27, 16, 32, 18, 500, persian, DateTimeKind.Local)
printfn $"""{date1.ToString "M/dd/yyyy h:mm:ss.fff tt"} {date1.Kind}"""
let sep = DateTimeFormatInfo.CurrentInfo.TimeSeparator
printfn $"{persian.GetMonth date1}/{persian.GetDayOfMonth date1}/{persian.GetYear date1} {persian.GetHour date1}{sep}{persian.GetMinute date1:D2}{sep}{persian.GetSecond date1:D2}.{persian.GetMilliseconds date1:G3} {date1.Kind}\n"

printfn "Using the Hijri Calendar:"
// Get current culture so it can later be restored.
let dftCulture = Thread.CurrentThread.CurrentCulture

// Define Hijri calendar.
let hijri = HijriCalendar()
// Make ar-SY the current culture and Hijri the current calendar.
Thread.CurrentThread.CurrentCulture <- CultureInfo "ar-SY"
let current = CultureInfo.CurrentCulture
current.DateTimeFormat.Calendar <- hijri

let dFormat = 
    let dFormat = current.DateTimeFormat.ShortDatePattern
    // Ensure year is displayed as four digits.
    Regex.Replace(dFormat, "/yy$", "/yyyy") + " H:mm:ss.fff"

let fmtString = "{0} culture using the {1} calendar: {2:" + dFormat + "} {3}"
let date2 = DateTime(1431, 9, 9, 16, 32, 18, 500, hijri, DateTimeKind.Local)
Console.WriteLine(fmtString, current, getCalendarName hijri, date2, date2.Kind)

// Restore previous culture.
Thread.CurrentThread.CurrentCulture <- dftCulture
let dFormat2 = DateTimeFormatInfo.CurrentInfo.ShortDatePattern + " H:mm:ss.fff"
let fmtString2 = "{0} culture using the {1} calendar: {2:" + dFormat2 + "} {3}"
Console.WriteLine(fmtString2, CultureInfo.CurrentCulture, getCalendarName CultureInfo.CurrentCulture.Calendar, date2, date2.Kind)


// The example displays the following output:
//    Using the Persian Calendar:
//    8/18/2010 4:32:18.500 PM Local
//    5/27/1389 16:32:18.500 Local
//
//    Using the Hijri Calendar:
//    ar-SY culture using the Hijri calendar: 09/09/1431 16:32:18.500 Local
//    en-US culture using the Gregorian calendar: 8/18/2010 16:32:18.500 Local
Imports System.Globalization
Imports System.Text.RegularExpressions
Imports System.Threading

Module Example
   Public Sub Main()
      Console.WriteLine("Using the Persian Calendar:")
      Dim persian As New PersianCalendar()
      Dim date1 As New Date(1389, 5, 27, 16, 32, 18, 500, _
                            persian, DateTimeKind.Local)
      Console.WriteLine("{0:M/dd/yyyy h:mm:ss.fff tt} {1}", date1, date1.Kind)
      Console.WriteLine("{0}/{1}/{2} {3}{8}{4:D2}{8}{5:D2}.{6:G3} {7}", _
                                       persian.GetMonth(date1), _
                                       persian.GetDayOfMonth(date1), _
                                       persian.GetYear(date1), _
                                       persian.GetHour(date1), _
                                       persian.GetMinute(date1), _
                                       persian.GetSecond(date1), _
                                       persian.GetMilliseconds(date1), _
                                       date1.Kind, _
                                       DateTimeFormatInfo.CurrentInfo.TimeSeparator)
      Console.WriteLine()
      
      Console.WriteLine("Using the Hijri Calendar:")
      ' Get current culture so it can later be restored.
      Dim dftCulture As CultureInfo = Thread.CurrentThread.CurrentCulture
      
      ' Define strings for use in composite formatting.
      Dim dFormat As String 
      Dim fmtString As String 
      ' Define Hijri calendar.
      Dim hijri As New HijriCalendar()
      ' Make ar-SY the current culture and Hijri the current calendar.
      Thread.CurrentThread.CurrentCulture = New CultureInfo("ar-SY")
      Dim current As CultureInfo = CultureInfo.CurrentCulture
      current.DateTimeFormat.Calendar = hijri
      dFormat = current.DateTimeFormat.ShortDatePattern
      ' Ensure year is displayed as four digits.
      dFormat = Regex.Replace(dFormat, "/yy$", "/yyyy") + " H:mm:ss.fff"
      fmtString = "{0} culture using the {1} calendar: {2:" + dFormat + "} {3}"
      Dim date2 As New Date(1431, 9, 9, 16, 32, 18, 500, _
                            hijri, DateTimeKind.Local)
      Console.WriteLine(fmtString, current, GetCalendarName(hijri), _
                        date2, date2.Kind) 

      ' Restore previous culture.
      Thread.CurrentThread.CurrentCulture = dftCulture
      dFormat = DateTimeFormatInfo.CurrentInfo.ShortDatePattern +" H:mm:ss.fff"
      fmtString = "{0} culture using the {1} calendar: {2:" + dFormat + "} {3}"
      Console.WriteLine(fmtString, CultureInfo.CurrentCulture, _
                        GetCalendarName(CultureInfo.CurrentCulture.Calendar), _
                        date2, date2.Kind) 
   End Sub
   
   Private Function GetCalendarName(cal As Calendar) As String
      Return Regex.Match(cal.ToString(), "\.(\w+)Calendar").Groups(1).Value
   End Function
End Module
' The example displays the following output:
'       Using the Persian Calendar:
'       8/18/2010 4:32:18.500 PM
'       5/27/1389 16:32:18.500
'       
'       Using the Hijri Calendar:
'       ar-SY culture using the Hijri calendar: 09/09/1431 16:32:18.500
'       en-US culture using the Gregorian calendar: 8/18/2010 16:32:18.500

설명

, monthday 매개 변수에 허용되는 year값은 매개 변수에 calendar 따라 달라집니다. 를 사용하여 calendar지정된 날짜와 시간을 표현할 수 없는 경우 예외가 throw됩니다.

날짜 및 시간 데이터 또는 제한 된 수준의 표준 시간대는 이식성 인식의 중요 한 애플리케이션을 사용할 수 있습니다 해당 DateTimeOffset 생성자입니다.

중요

일본어 달력의 시대는 천황 통치 기간을 기준으로 하므로 변경되어야 합니다. 예를 들어 2019년 5월 1일은 JapaneseCalendarJapaneseLunisolarCalendar에서 레이와 시대의 시작을 나타냅니다. 이러한 시대 변경 내용은 해당 달력을 사용하는 모든 애플리케이션에 영향을 줍니다. 자세한 내용과 애플리케이션이 영향을 받는지 여부를 확인하려면 .NET의 일본 달력에서 새 시대 처리를 참조하세요. Windows 시스템에서 애플리케이션을 테스트하여 시대 변화에 대한 준비 상태를 확인하는 방법에 대한 자세한 내용은 일본 시대 변화를 위한 애플리케이션 준비를 참조하세요. 여러 시대가 있는 달력을 지원하는 .NET의 기능과 여러 시대를 지원하는 달력으로 작업할 때 모범 사례는 시대 작업을 참조하세요.

네임스페이 System.Globalization 스는 및 JulianCalendar을 비롯한 GregorianCalendar 여러 일정을 제공합니다.

적용 대상

DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)

DateTime 구조체의 새 인스턴스를 지정된 달력의 지정된 연도, 월, 일, 시, 분, 초, 밀리초 및 UTC(협정 세계시) 또는 현지 시간으로 초기화합니다.

public:
 DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond);
public DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond);
new DateTime : int * int * int * int * int * int * int * int -> DateTime
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, millisecond As Integer, microsecond As Integer)

매개 변수

year
Int32

연도(1부터 9999까지)

month
Int32

월(1부터 12까지)

day
Int32

일(1부터 month에 있는 일수까지)

hour
Int32

시(0부터 23까지)

minute
Int32

분(0부터 59까지)

second
Int32

초(0부터 59까지)

millisecond
Int32

밀리초(0부터 999까지)

microsecond
Int32

마이크로초(0~999)입니다.

예외

year가 1보다 작거나 9999보다 큽니다.

또는

month가 1보다 작거나 12보다 큽니다.

또는

day 가 1보다 작거나 month의 일 수보다 큽니다.

또는

hour가 0보다 작거나 23보다 큽니다.

또는

minute가 0보다 작거나 59보다 큽니다.

또는

second가 0보다 작거나 59보다 큽니다.

또는

millisecond가 0보다 작거나 999보다 큽니다.

또는

microsecond가 0보다 작거나 999보다 큽니다.

설명

이 생성자는 및 를 yearmonthday 그레고리오력의 1년, 월 및 일로 해석합니다. 다른 달력에서 DateTime 연도, 월 및 일을 사용하여 값을 인스턴스화하려면 생성자를 호출합니다 DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar) .

Kind 속성이 Unspecified으로 초기화됩니다.

날짜 및 시간 데이터 또는 제한 된 수준의 표준 시간대는 이식성 인식의 중요 한 애플리케이션을 사용할 수 있습니다 해당 DateTimeOffset 생성자입니다.

적용 대상

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

DateTime 구조체의 새 인스턴스를 지정된 달력에서 지정된 연도, 월, 일, 시, 분, 초 및 밀리초로 초기화합니다.

public:
 DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, System::Globalization::Calendar ^ calendar);
public DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond, System.Globalization.Calendar calendar);
new DateTime : int * int * int * int * int * int * int * System.Globalization.Calendar -> DateTime
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, millisecond As Integer, calendar As Calendar)

매개 변수

year
Int32

연도(1부터 calendar에 있는 연수까지)

month
Int32

월(1부터 calendar에 있는 월수까지)

day
Int32

일(1부터 month에 있는 일수까지)

hour
Int32

시(0부터 23까지)

minute
Int32

분(0부터 59까지)

second
Int32

초(0부터 59까지)

millisecond
Int32

밀리초(0부터 999까지)

calendar
Calendar

year, monthday를 해석하는 데 사용되는 달력입니다.

예외

calendar이(가) null인 경우

yearcalendar에서 지원되는 범위에 없습니다.

또는

month가 1보다 작거나 calendar의 개월 수보다 큽니다.

또는

day 가 1보다 작거나 month의 일 수보다 큽니다.

또는

hour가 0보다 작거나 23보다 큽니다.

또는

minute가 0보다 작거나 59보다 큽니다.

또는

second가 0보다 작거나 59보다 큽니다.

또는

millisecond가 0보다 작거나 999보다 큽니다.

예제

다음 예제에서는 생성자를 두 번 호출 DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar) 하여 두 DateTime 값을 인스턴스화합니다. 첫 번째 호출은 개체를 DateTime 사용하여 PersianCalendar 값을 인스턴스화합니다. 페르시아 달력은 문화권의 기본 달력으로 지정할 수 없으므로 페르시아 달력에 날짜를 표시하려면 , PersianCalendar.GetDayOfMonthPersianCalendar.GetYear 메서드에 대한 개별 호출이 PersianCalendar.GetMonth필요합니다. 생성자에 대한 두 번째 호출은 개체를 DateTime 사용하여 HijriCalendar 값을 인스턴스화합니다. 이 예제에서는 현재 문화권을 아랍어(시리아)로 변경하고 현재 문화권의 기본 달력을 Hijri 달력으로 변경합니다. Hijri는 현재 문화권의 기본 달력이므로 메서드는 Console.WriteLine 이를 사용하여 날짜의 서식을 지정합니다. 이전 현재 문화권(이 경우 영어(미국))이 복원되면 Console.WriteLine 메서드는 현재 문화권의 기본 그레고리오력 을 사용하여 날짜 서식을 지정합니다.

using System;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Threading;

public class Example
{
   public static void Main()
   {
      Console.WriteLine("Using the Persian Calendar:");
      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);

      Console.WriteLine("Using the Hijri Calendar:");
      // Get current culture so it can later be restored.
      CultureInfo dftCulture = Thread.CurrentThread.CurrentCulture;

      // Define strings for use in composite formatting.
      string dFormat;
      string fmtString;
      // Define Hijri calendar.
      HijriCalendar hijri = new HijriCalendar();
      // Make ar-SY the current culture and Hijri the current calendar.
      Thread.CurrentThread.CurrentCulture = new CultureInfo("ar-SY");
      CultureInfo current = CultureInfo.CurrentCulture;
      current.DateTimeFormat.Calendar = hijri;
      dFormat = current.DateTimeFormat.ShortDatePattern;
      // Ensure year is displayed as four digits.
      dFormat = Regex.Replace(dFormat, "/yy$", "/yyyy") + " H:mm:ss.fff";
      fmtString = "{0} culture using the {1} calendar: {2:" + dFormat + "}";
      DateTime date2 = new DateTime(1431, 9, 9, 16, 32, 18, 500, hijri);
      Console.WriteLine(fmtString, current, GetCalendarName(hijri), date2);

      // Restore previous culture.
      Thread.CurrentThread.CurrentCulture = dftCulture;
      dFormat = DateTimeFormatInfo.CurrentInfo.ShortDatePattern +" H:mm:ss.fff";
      fmtString = "{0} culture using the {1} calendar: {2:" + dFormat + "}";
      Console.WriteLine(fmtString,
                        CultureInfo.CurrentCulture,
                        GetCalendarName(CultureInfo.CurrentCulture.Calendar),
                        date2);
   }

   private static string GetCalendarName(Calendar cal)
   {
      return Regex.Match(cal.ToString(), "\\.(\\w+)Calendar").Groups[1].Value;
   }
}
// The example displays the following output:
//       8/18/2010 4:32:18.500 PM
//       5/27/1389 16:32:18.500
//
//       Using the Hijri Calendar:
//       ar-SY culture using the Hijri calendar: 09/09/1431 16:32:18.500
//       en-US culture using the Gregorian calendar: 8/18/2010 16:32:18.500
open System
open System.Globalization
open System.Text.RegularExpressions
open System.Threading

let getCalendarName (cal: Calendar) =
      Regex.Match(string cal, "\\.(\\w+)Calendar").Groups[1].Value

printfn "Using the Persian Calendar:"
let persian = PersianCalendar()
let date1 = DateTime(1389, 5, 27, 16, 32, 18, 500, persian)
printfn $"""{date1.ToString("M/dd/yyyy h:mm:ss.fff tt")}"""
let sep = DateTimeFormatInfo.CurrentInfo.TimeSeparator
printfn $"{persian.GetMonth date1}/{persian.GetDayOfMonth date1}/{persian.GetYear date1} {persian.GetHour date1}{sep}%02i{persian.GetMinute date1}{sep}%02i{persian.GetSecond date1}.%.3f{persian.GetMilliseconds date1}\n"

printfn "Using the Hijri Calendar:"
// Get current culture so it can later be restored.
let dftCulture = Thread.CurrentThread.CurrentCulture

// Define Hijri calendar.
let hijri = HijriCalendar()
// Make ar-SY the current culture and Hijri the current calendar.
Thread.CurrentThread.CurrentCulture <- CultureInfo "ar-SY"
let current = CultureInfo.CurrentCulture
current.DateTimeFormat.Calendar <- hijri

let dFormat = 
    let dFormat = current.DateTimeFormat.ShortDatePattern
    // Ensure year is displayed as four digits.
    Regex.Replace(dFormat, "/yy$", "/yyyy") + " H:mm:ss.fff"

let fmtString = "{0} culture using the {1} calendar: {2:" + dFormat + "}"
let date2 = DateTime(1431, 9, 9, 16, 32, 18, 500, hijri)
Console.WriteLine(fmtString, current, getCalendarName hijri, date2)

// Restore previous culture.
Thread.CurrentThread.CurrentCulture <- dftCulture
let dFormat2 = DateTimeFormatInfo.CurrentInfo.ShortDatePattern + " H:mm:ss.fff"
let fmtString2 = "{0} culture using the {1} calendar: {2:" + dFormat + "}"
Console.WriteLine(fmtString2, CultureInfo.CurrentCulture, getCalendarName CultureInfo.CurrentCulture.Calendar, date2)


// The example displays the following output:
//       8/18/2010 4:32:18.500 PM
//       5/27/1389 16:32:18.500
//
//       Using the Hijri Calendar:
//       ar-SY culture using the Hijri calendar: 09/09/1431 16:32:18.500
//       en-US culture using the Gregorian calendar: 8/18/2010 16:32:18.500
Imports System.Globalization
Imports System.Text.RegularExpressions
Imports System.Threading

Module Example
   Public Sub Main()
      Console.WriteLine("Using the Persian Calendar:")
      Dim persian As New PersianCalendar()
      Dim date1 As New Date(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}", _
                                       persian.GetMonth(date1), _
                                       persian.GetDayOfMonth(date1), _
                                       persian.GetYear(date1), _
                                       persian.GetHour(date1), _
                                       persian.GetMinute(date1), _
                                       persian.GetSecond(date1), _
                                       persian.GetMilliseconds(date1), _
                                       DateTimeFormatInfo.CurrentInfo.TimeSeparator)
      Console.WriteLine()
      
      Console.WriteLine("Using the Hijri Calendar:")
      ' Get current culture so it can later be restored.
      Dim dftCulture As CultureInfo = Thread.CurrentThread.CurrentCulture
      
      ' Define strings for use in composite formatting.
      Dim dFormat As String 
      Dim fmtString As String 
      ' Define Hijri calendar.
      Dim hijri As New HijriCalendar()
      ' Make ar-SY the current culture and Hijri the current calendar.
      Thread.CurrentThread.CurrentCulture = New CultureInfo("ar-SY")
      Dim current As CultureInfo = CultureInfo.CurrentCulture
      current.DateTimeFormat.Calendar = hijri
      dFormat = current.DateTimeFormat.ShortDatePattern
      ' Ensure year is displayed as four digits.
      dFormat = Regex.Replace(dFormat, "/yy$", "/yyyy") + " H:mm:ss.fff"
      fmtString = "{0} culture using the {1} calendar: {2:" + dFormat + "}"
      Dim date2 As New Date(1431, 9, 9, 16, 32, 18, 500, hijri)
      Console.WriteLine(fmtString, current, GetCalendarName(hijri), date2) 

      ' Restore previous culture.
      Thread.CurrentThread.CurrentCulture = dftCulture
      dFormat = DateTimeFormatInfo.CurrentInfo.ShortDatePattern +" H:mm:ss.fff"
      fmtString = "{0} culture using the {1} calendar: {2:" + dFormat + "}"
      Console.WriteLine(fmtString, CultureInfo.CurrentCulture, _
                        GetCalendarName(CultureInfo.CurrentCulture.Calendar), _
                        date2) 
   End Sub
   
   Private Function GetCalendarName(cal As Calendar) As String
      Return Regex.Match(cal.ToString(), "\.(\w+)Calendar").Groups(1).Value
   End Function
End Module
' The example displays the following output:
'       Using the Persian Calendar:
'       8/18/2010 4:32:18.500 PM
'       5/27/1389 16:32:18.500
'       
'       Using the Hijri Calendar:
'       ar-SY culture using the Hijri calendar: 09/09/1431 16:32:18.500
'       en-US culture using the Gregorian calendar: 8/18/2010 16:32:18.500

설명

Kind 속성이 Unspecified으로 초기화됩니다.

, monthday 에 허용되는 year값은 에 따라 calendar달라집니다. 를 사용하여 calendar지정된 날짜와 시간을 표현할 수 없는 경우 예외가 throw됩니다.

날짜 및 시간 데이터 또는 제한 된 수준의 표준 시간대는 이식성 인식의 중요 한 애플리케이션을 사용할 수 있습니다 해당 DateTimeOffset 생성자입니다.

중요

일본어 달력의 시대는 천황 통치 기간을 기준으로 하므로 변경되어야 합니다. 예를 들어 2019년 5월 1일은 JapaneseCalendarJapaneseLunisolarCalendar에서 레이와 시대의 시작을 나타냅니다. 이러한 시대 변경 내용은 해당 달력을 사용하는 모든 애플리케이션에 영향을 줍니다. 자세한 내용과 애플리케이션이 영향을 받는지 여부를 확인하려면 .NET에서 일본 달력의 새 시대 처리를 참조하세요. Windows 시스템에서 애플리케이션을 테스트하여 시대 변화에 대한 준비 상태를 확인하는 방법에 대한 자세한 내용은 일본 시대 변화에 맞게 애플리케이션 준비를 참조하세요. 여러 시대가 있는 달력을 지원하는 .NET의 기능과 여러 연대를 지원하는 달력으로 작업할 때 모범 사례는 연대 작업을 참조하세요.

네임스페이 System.Globalization 스는 및 JulianCalendar을 비롯한 GregorianCalendar 여러 일정을 제공합니다.

추가 정보

적용 대상

DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind)

DateTime 구조체의 새 인스턴스를 지정된 연도, 월, 일, 시, 분, 초, 밀리초 및 UTC(협정 세계시) 또는 현지 시간으로 초기화합니다.

public:
 DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, DateTimeKind kind);
public DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond, DateTimeKind kind);
new DateTime : int * int * int * int * int * int * int * DateTimeKind -> DateTime
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, millisecond As Integer, kind As DateTimeKind)

매개 변수

year
Int32

연도(1부터 9999까지)

month
Int32

월(1부터 12까지)

day
Int32

일(1부터 month에 있는 일수까지)

hour
Int32

시(0부터 23까지)

minute
Int32

분(0부터 59까지)

second
Int32

초(0부터 59까지)

millisecond
Int32

밀리초(0부터 999까지)

kind
DateTimeKind

year, month, day, hour, minute, secondmillisecond가 현지 시간 또는 UTC(협정 세계시)를 지정하는지, 아니면 둘 다 지정하지 않는지를 나타내는 열거형 값 중 하나입니다.

예외

year가 1보다 작거나 9999보다 큽니다.

또는

month가 1보다 작거나 12보다 큽니다.

또는

day 가 1보다 작거나 month의 일 수보다 큽니다.

또는

hour가 0보다 작거나 23보다 큽니다.

또는

minute가 0보다 작거나 59보다 큽니다.

또는

second가 0보다 작거나 59보다 큽니다.

또는

millisecond가 0보다 작거나 999보다 큽니다.

kindDateTimeKind 값 중 하나가 아닙니다.

예제

다음 예제에서는 생성자를 사용하여 DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind) 값을 인스턴스화합니다 DateTime .

DateTime date1 = new DateTime(2010, 8, 18, 16, 32, 18, 500,
                              DateTimeKind.Local);
Console.WriteLine("{0:M/dd/yyyy h:mm:ss.fff tt} {1}", date1, date1.Kind);
// The example displays the following output, in this case for en-us culture:
//      8/18/2010 4:32:18.500 PM Local
let date1 = DateTime(2010, 8, 18, 16, 32, 18, 500, DateTimeKind.Local)
printfn $"""{date1.ToString "M/dd/yyyy h:mm:ss.fff tt"} {date1.Kind}"""

// The example displays the following output, in this case for en-us culture:
//      8/18/2010 4:32:18.500 PM Local
Dim date1 As New Date(2010, 8, 18, 16, 32, 18, 500, DateTimeKind.Local)
Console.WriteLine("{0:M/dd/yyyy h:mm:ss.fff tt} {1}", date1, date1.Kind)
' The example displays the following output:
'      8/18/2010 4:32:18.500 PM Local

설명

이 생성자는 및 를yearmonthday 그레고리력의 연도, 월 및 일로 해석합니다. 다른 달력에서 DateTime 연도, 월 및 일을 사용하여 값을 인스턴스화하려면 생성자를 호출 DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, DateTimeKind) 합니다.

날짜 및 시간 데이터 또는 제한 된 수준의 표준 시간대는 이식성 인식의 중요 한 애플리케이션을 사용할 수 있습니다 해당 DateTimeOffset 생성자입니다.

적용 대상

DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32)

DateTime 구조체의 새 인스턴스를 지정된 연도, 월, 일, 시, 분, 초 및 밀리초로 초기화합니다.

public:
 DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond);
public DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond);
new DateTime : int * int * int * int * int * int * int -> DateTime
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, millisecond As Integer)

매개 변수

year
Int32

연도(1부터 9999까지)

month
Int32

월(1부터 12까지)

day
Int32

일(1부터 month에 있는 일수까지)

hour
Int32

시(0부터 23까지)

minute
Int32

분(0부터 59까지)

second
Int32

초(0부터 59까지)

millisecond
Int32

밀리초(0부터 999까지)

예외

year가 1보다 작거나 9999보다 큽니다.

또는

month가 1보다 작거나 12보다 큽니다.

또는

day 가 1보다 작거나 month의 일 수보다 큽니다.

또는

hour가 0보다 작거나 23보다 큽니다.

또는

minute가 0보다 작거나 59보다 큽니다.

또는

second가 0보다 작거나 59보다 큽니다.

또는

millisecond가 0보다 작거나 999보다 큽니다.

예제

다음 예제에서는 생성자를 사용하여 DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32) 값을 인스턴스화합니다 DateTime .

DateTime date1 = new DateTime(2010, 8, 18, 16, 32, 18, 500);
Console.WriteLine(date1.ToString("M/dd/yyyy h:mm:ss.fff tt"));
// The example displays the following output, in this case for en-us culture:
//      8/18/2010 4:32:18.500 PM
let date1 = DateTime(2010, 8, 18, 16, 32, 18, 500)

date1.ToString "M/dd/yyyy h:mm:ss.fff tt"
|> printfn "%s"

// The example displays the following output, in this case for en-us culture:
//      8/18/2010 4:32:18.500 PM
Dim date1 As New Date(2010, 8, 18, 16, 32, 18, 500)
Console.WriteLine(date1.ToString("M/dd/yyyy h:mm:ss.fff tt"))
' The example displays the following output:
'      8/18/2010 4:32:18.500 PM

설명

이 생성자는 및 를yearmonthday 그레고리력의 연도, 월 및 일로 해석합니다. 다른 달력에서 DateTime 연도, 월 및 일을 사용하여 값을 인스턴스화하려면 생성자를 호출 DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar) 합니다.

Kind 속성이 Unspecified으로 초기화됩니다.

날짜 및 시간 데이터 또는 제한 된 수준의 표준 시간대는 이식성 인식의 중요 한 애플리케이션을 사용할 수 있습니다 해당 DateTimeOffset 생성자입니다.

추가 정보

적용 대상

DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, DateTimeKind)

DateTime 구조체의 새 인스턴스를 지정된 달력의 지정된 연도, 월, 일, 시, 분, 초, 밀리초 및 UTC(협정 세계시) 또는 현지 시간으로 초기화합니다.

public:
 DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond, System::Globalization::Calendar ^ calendar, DateTimeKind kind);
public DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond, System.Globalization.Calendar calendar, DateTimeKind kind);
new DateTime : int * int * int * int * int * int * int * int * System.Globalization.Calendar * DateTimeKind -> DateTime
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, millisecond As Integer, microsecond As Integer, calendar As Calendar, kind As DateTimeKind)

매개 변수

year
Int32

연도(1부터 calendar에 있는 연수까지)

month
Int32

월(1부터 calendar에 있는 월수까지)

day
Int32

일(1부터 month에 있는 일수까지)

hour
Int32

시(0부터 23까지)

minute
Int32

분(0부터 59까지)

second
Int32

초(0부터 59까지)

millisecond
Int32

밀리초(0부터 999까지)

microsecond
Int32

마이크로초(0~999)입니다.

calendar
Calendar

year, monthday를 해석하는 데 사용되는 달력입니다.

kind
DateTimeKind

year, month, day, hour, minute, secondmillisecond가 현지 시간 또는 UTC(협정 세계시)를 지정하는지, 아니면 둘 다 지정하지 않는지를 나타내는 열거형 값 중 하나입니다.

예외

calendarnull입니다.

yearcalendar에서 지원되는 범위에 없습니다.

또는

month가 1보다 작거나 calendar의 개월 수보다 큽니다.

또는

day 가 1보다 작거나 month의 일 수보다 큽니다.

또는

hour가 0보다 작거나 23보다 큽니다.

또는

minute가 0보다 작거나 59보다 큽니다.

또는

second가 0보다 작거나 59보다 큽니다.

또는

millisecond가 0보다 작거나 999보다 큽니다.

또는

microsecond가 0보다 작거나 999보다 큽니다.

kindDateTimeKind 값 중 하나가 아닙니다.

설명

, monthday 매개 변수에 허용되는 year값은 매개 변수에 calendar 따라 달라집니다. 를 사용하여 calendar지정된 날짜와 시간을 표현할 수 없는 경우 예외가 throw됩니다.

날짜 및 시간 데이터 또는 제한 된 수준의 표준 시간대는 이식성 인식의 중요 한 애플리케이션을 사용할 수 있습니다 해당 DateTimeOffset 생성자입니다.

적용 대상

DateTime(Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind)

DateTime 구조체의 새 인스턴스를 지정된 연도, 월, 일, 시, 분, 초 및 UTC(협정 세계시) 또는 현지 시간으로 초기화합니다.

public:
 DateTime(int year, int month, int day, int hour, int minute, int second, DateTimeKind kind);
public DateTime (int year, int month, int day, int hour, int minute, int second, DateTimeKind kind);
new DateTime : int * int * int * int * int * int * DateTimeKind -> DateTime
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, kind As DateTimeKind)

매개 변수

year
Int32

연도(1부터 9999까지)

month
Int32

월(1부터 12까지)

day
Int32

일(1부터 month에 있는 일수까지)

hour
Int32

시(0부터 23까지)

minute
Int32

분(0부터 59까지)

second
Int32

초(0부터 59까지)

kind
DateTimeKind

year, month, day, hour, minutesecond가 현지 시간 또는 UTC(협정 세계시)를 지정하는지, 아니면 둘 다 지정하지 않는지를 나타내는 열거형 값 중 하나입니다.

예외

year가 1보다 작거나 9999보다 큽니다.

또는

month가 1보다 작거나 12보다 큽니다.

또는

day 가 1보다 작거나 month의 일 수보다 큽니다.

또는

hour가 0보다 작거나 23보다 큽니다.

또는

minute가 0보다 작거나 59보다 큽니다.

또는

second가 0보다 작거나 59보다 큽니다.

kindDateTimeKind 값 중 하나가 아닙니다.

예제

다음 예제에서는 생성자를 사용하여 DateTime(Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind) 값을 인스턴스화합니다 DateTime .

DateTime date1 = new DateTime(2010, 8, 18, 16, 32, 0, DateTimeKind.Local);
Console.WriteLine("{0} {1}", date1, date1.Kind);
// The example displays the following output, in this case for en-us culture:
//      8/18/2010 4:32:00 PM Local
let date1 = DateTime(2010, 8, 18, 16, 32, 0, DateTimeKind.Local)
printfn $"{date1} {date1.Kind}"

// The example displays the following output, in this case for en-us culture:
//      8/18/2010 4:32:00 PM Local
Dim date1 As New Date(2010, 8, 18, 16, 32, 0, DateTimeKind.Local)
Console.WriteLine("{0} {1}", date1, date1.Kind)
' The example displays the following output:
'      8/18/2010 4:32:00 PM Local

설명

이 생성자는 및 를yearmonthday 그레고리오력의 1년, 월 및 일로 해석합니다. 다른 달력에서 DateTime 연도, 월 및 일을 사용하여 값을 인스턴스화하려면 생성자를 호출합니다 DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, DateTimeKind) .

날짜 및 시간 데이터 또는 제한 된 수준의 표준 시간대는 이식성 인식의 중요 한 애플리케이션을 사용할 수 있습니다 해당 DateTimeOffset 생성자입니다.

적용 대상

DateTime(Int32, Int32, Int32, Int32, Int32, Int32)

DateTime 구조체의 새 인스턴스를 지정된 연도, 월, 날짜, 시, 분 및 초로 초기화합니다.

public:
 DateTime(int year, int month, int day, int hour, int minute, int second);
public DateTime (int year, int month, int day, int hour, int minute, int second);
new DateTime : int * int * int * int * int * int -> DateTime
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer)

매개 변수

year
Int32

연도(1부터 9999까지)

month
Int32

월(1부터 12까지)

day
Int32

일(1부터 month에 있는 일수까지)

hour
Int32

시(0부터 23까지)

minute
Int32

분(0부터 59까지)

second
Int32

초(0부터 59까지)

예외

year가 1보다 작거나 9999보다 큽니다.

또는

month가 1보다 작거나 12보다 큽니다.

또는

day 가 1보다 작거나 month의 일 수보다 큽니다.

또는

hour가 0보다 작거나 23보다 큽니다.

또는

minute가 0보다 작거나 59보다 큽니다.

또는

second가 0보다 작거나 59보다 큽니다.

예제

다음 예제에서는 생성자를 사용하여 DateTime 값을 인스턴스화합니다 DateTime .

DateTime date1 = new DateTime(2010, 8, 18, 16, 32, 0);
Console.WriteLine(date1.ToString());
// The example displays the following output, in this case for en-us culture:
//      8/18/2010 4:32:00 PM
let date1 = DateTime(2010, 8, 18, 16, 32, 0)
printfn $"{date1}"

// The example displays the following output, in this case for en-us culture:
//      8/18/2010 4:32:00 PM
Dim date1 As New Date(2010, 8, 18, 16, 32, 0)
Console.WriteLine(date1.ToString())
' The example displays the following output:
'      8/18/2010 4:32:00 PM

설명

Kind 속성이 Unspecified으로 초기화됩니다.

이 생성자는 및 를yearmonthday 그레고리오력의 1년, 월 및 일로 해석합니다. 다른 달력에서 DateTime 연도, 월 및 일을 사용하여 값을 인스턴스화하려면 생성자를 호출합니다 DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Calendar) .

날짜 및 시간 데이터 또는 제한 된 수준의 표준 시간대는 이식성 인식의 중요 한 애플리케이션을 사용할 수 있습니다 해당 DateTimeOffset 생성자입니다.

적용 대상

DateTime(Int32, Int32, Int32, Calendar)

DateTime 구조체의 새 인스턴스를 지정된 달력의 지정된 연도, 월 및 날짜로 초기화합니다.

public:
 DateTime(int year, int month, int day, System::Globalization::Calendar ^ calendar);
public DateTime (int year, int month, int day, System.Globalization.Calendar calendar);
new DateTime : int * int * int * System.Globalization.Calendar -> DateTime
Public Sub New (year As Integer, month As Integer, day As Integer, calendar As Calendar)

매개 변수

year
Int32

연도(1부터 calendar에 있는 연수까지)

month
Int32

월(1부터 calendar에 있는 월수까지)

day
Int32

일(1부터 month에 있는 일수까지)

calendar
Calendar

year, monthday를 해석하는 데 사용되는 달력입니다.

예외

calendar이(가) null인 경우

yearcalendar에서 지원되는 범위에 없습니다.

또는

month가 1보다 작거나 calendar의 개월 수보다 큽니다.

또는

day 가 1보다 작거나 month의 일 수보다 큽니다.

예제

다음 예제에서는 생성자를 두 번 호출 DateTime(Int32, Int32, Int32, Calendar) 하여 두 DateTime 값을 인스턴스화합니다. 첫 번째 호출은 개체를 DateTime 사용하여 PersianCalendar 값을 인스턴스화합니다. 페르시아 달력은 문화권의 기본 달력으로 지정할 수 없으므로 페르시아 달력에 날짜를 표시하려면 , PersianCalendar.GetDayOfMonthPersianCalendar.GetYear 메서드에 대한 개별 호출이 PersianCalendar.GetMonth필요합니다. 생성자에 대한 두 번째 호출은 개체를 DateTime 사용하여 HijriCalendar 값을 인스턴스화합니다. 이 예제에서는 현재 문화권을 아랍어(시리아)로 변경하고 현재 문화권의 기본 달력을 Hijri 달력으로 변경합니다. Hijri는 현재 문화권의 기본 달력이므로 메서드는 Console.WriteLine 이를 사용하여 날짜의 서식을 지정합니다. 이전 현재 문화권(이 경우 영어(미국))이 복원되면 Console.WriteLine 메서드는 현재 문화권의 기본 그레고리오력 을 사용하여 날짜 서식을 지정합니다.

using System;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Threading;

public class Example
{
   public static void Main()
   {
      Console.WriteLine("Using the Persian Calendar:");
      PersianCalendar persian = new PersianCalendar();
      DateTime date1 = new DateTime(1389, 5, 27, persian);
      Console.WriteLine(date1.ToString());
      Console.WriteLine("{0}/{1}/{2}\n", persian.GetMonth(date1),
                                       persian.GetDayOfMonth(date1),
                                       persian.GetYear(date1));

      Console.WriteLine("Using the Hijri Calendar:");
      // Get current culture so it can later be restored.
      CultureInfo dftCulture = Thread.CurrentThread.CurrentCulture;

      // Define Hijri calendar.
      HijriCalendar hijri = new HijriCalendar();
      // Make ar-SY the current culture and Hijri the current calendar.
      Thread.CurrentThread.CurrentCulture = new CultureInfo("ar-SY");
      CultureInfo current = CultureInfo.CurrentCulture;
      current.DateTimeFormat.Calendar = hijri;
      string dFormat = current.DateTimeFormat.ShortDatePattern;
      // Ensure year is displayed as four digits.
      dFormat = Regex.Replace(dFormat, "/yy$", "/yyyy");
      current.DateTimeFormat.ShortDatePattern = dFormat;
      DateTime date2 = new DateTime(1431, 9, 9, hijri);
      Console.WriteLine("{0} culture using the {1} calendar: {2:d}", current,
                        GetCalendarName(hijri), date2);

      // Restore previous culture.
      Thread.CurrentThread.CurrentCulture = dftCulture;
      Console.WriteLine("{0} culture using the {1} calendar: {2:d}",
                        CultureInfo.CurrentCulture,
                        GetCalendarName(CultureInfo.CurrentCulture.Calendar),
                        date2);
   }

   private static string GetCalendarName(Calendar cal)
   {
      return Regex.Match(cal.ToString(), "\\.(\\w+)Calendar").Groups[1].Value;
   }
}
// The example displays the following output:
//       Using the Persian Calendar:
//       8/18/2010 12:00:00 AM
//       5/27/1389
//
//       Using the Hijri Calendar:
//       ar-SY culture using the Hijri calendar: 09/09/1431
//       en-US culture using the Gregorian calendar: 8/18/2010
open System
open System.Globalization
open System.Text.RegularExpressions
open System.Threading

let getCalendarName (cal: Calendar) =
    Regex.Match(string cal, "\\.(\\w+)Calendar").Groups[1].Value

printfn "Using the Persian Calendar:"
let persian = PersianCalendar()
let date1 = DateTime(1389, 5, 27, persian)
printfn $"{date1}"
printfn $"{persian.GetMonth date1}/{persian.GetDayOfMonth date1}/{persian.GetYear date1}\n"

printfn "Using the Hijri Calendar:"
// Get current culture so it can later be restored.
let dftCulture = Thread.CurrentThread.CurrentCulture

// Define Hijri calendar.
let hijri = HijriCalendar()
// Make ar-SY the current culture and Hijri the current calendar.
Thread.CurrentThread.CurrentCulture <- CultureInfo "ar-SY"
let current = CultureInfo.CurrentCulture
current.DateTimeFormat.Calendar <- hijri

let dFormat =
    let dFormat = current.DateTimeFormat.ShortDatePattern
    // Ensure year is displayed as four digits.
    Regex.Replace(dFormat, "/yy$", "/yyyy")

current.DateTimeFormat.ShortDatePattern <- dFormat
let date2 = DateTime(1431, 9, 9, hijri)
printfn $"{current} culture using the {getCalendarName hijri} calendar: {date2:d}"

// Restore previous culture.
Thread.CurrentThread.CurrentCulture <- dftCulture
printfn $"{CultureInfo.CurrentCulture} culture using the {getCalendarName CultureInfo.CurrentCulture.Calendar} calendar: {date2:d}"


// The example displays the following output:
//       Using the Persian Calendar:
//       8/18/2010 12:00:00 AM
//       5/27/1389
//
//       Using the Hijri Calendar:
//       ar-SY culture using the Hijri calendar: 09/09/1431
//       en-US culture using the Gregorian calendar: 8/18/2010
Imports System.Globalization
Imports System.Text.RegularExpressions
Imports System.Threading

Module Example
   Public Sub Main()
      Console.WriteLine("Using the Persian Calendar:")
      Dim persian As New PersianCalendar()
      Dim date1 As New Date(1389, 5, 27, persian)
      Console.WriteLine(date1.ToString())
      Console.WriteLine("{0}/{1}/{2}", persian.GetMonth(date1), _
                                       persian.GetDayOfMonth(date1), _
                                       persian.GetYear(date1))
      Console.WriteLine()
      
      Console.WriteLine("Using the Hijri Calendar:")
      ' Get current culture so it can later be restored.
      Dim dftCulture As CultureInfo = Thread.CurrentThread.CurrentCulture
      
      ' Define Hijri calendar.
      Dim hijri As New HijriCalendar()
      ' Make ar-SY the current culture and Hijri the current calendar.
      Thread.CurrentThread.CurrentCulture = New CultureInfo("ar-SY")
      Dim current As CultureInfo = CultureInfo.CurrentCulture
      current.DateTimeFormat.Calendar = hijri
      Dim dFormat As String = current.DateTimeFormat.ShortDatePattern
      ' Ensure year is displayed as four digits.
      dFormat = Regex.Replace(dFormat, "/yy$", "/yyyy")
      current.DateTimeFormat.ShortDatePattern = dFormat
      Dim date2 As New Date(1431, 9, 9, hijri)
      Console.WriteLine("{0} culture using the {1} calendar: {2:d}", current, _
                        GetCalendarName(hijri), date2) 
      
      ' Restore previous culture.
      Thread.CurrentThread.CurrentCulture = dftCulture
      Console.WriteLine("{0} culture using the {1} calendar: {2:d}", _
                        CultureInfo.CurrentCulture, _
                        GetCalendarName(CultureInfo.CurrentCulture.Calendar), _
                        date2) 
   End Sub
   
   Private Function GetCalendarName(cal As Calendar) As String
      Return Regex.Match(cal.ToString(), "\.(\w+)Calendar").Groups(1).Value
   End Function
End Module
' The example displays the following output:
'       Using the Persian Calendar:
'       8/18/2010 12:00:00 AM
'       5/27/1389
'       
'       Using the Hijri Calendar:
'       ar-SY culture using the Hijri calendar: 09/09/1431
'       en-US culture using the Gregorian calendar: 8/18/2010

설명

결과 DateTime 날짜의 시간은 자정(00:00:00)입니다. Kind 속성이 Unspecified으로 초기화됩니다.

, monthday 에 허용되는 year값은 에 calendar따라 달라집니다. 를 사용하여 calendar지정된 날짜와 시간을 표현할 수 없는 경우 예외가 throw됩니다.

중요

일본어 달력의 시대는 천황 통치 기간을 기준으로 하므로 변경되어야 합니다. 예를 들어 2019년 5월 1일은 JapaneseCalendarJapaneseLunisolarCalendar에서 레이와 시대의 시작을 나타냅니다. 이러한 시대 변경 내용은 해당 달력을 사용하는 모든 애플리케이션에 영향을 줍니다. 자세한 내용과 애플리케이션이 영향을 받는지 여부를 확인하려면 .NET의 일본 달력에서 새 시대 처리를 참조하세요. Windows 시스템에서 애플리케이션을 테스트하여 시대 변화에 대한 준비 상태를 확인하는 방법에 대한 자세한 내용은 일본 시대 변화를 위한 애플리케이션 준비를 참조하세요. 여러 시대가 있는 달력을 지원하는 .NET의 기능과 여러 시대를 지원하는 달력으로 작업할 때 모범 사례는 시대 작업을 참조하세요.

네임스페이 System.Globalization 스는 및 JulianCalendar을 비롯한 GregorianCalendar 여러 일정을 제공합니다.

추가 정보

적용 대상

DateTime(Int32, Int32, Int32)

DateTime 구조체의 새 인스턴스를 특정 연도, 월 및 날짜로 초기화합니다.

public:
 DateTime(int year, int month, int day);
public DateTime (int year, int month, int day);
new DateTime : int * int * int -> DateTime
Public Sub New (year As Integer, month As Integer, day As Integer)

매개 변수

year
Int32

연도(1부터 9999까지)

month
Int32

월(1부터 12까지)

day
Int32

일(1부터 month에 있는 일수까지)

예외

year가 1보다 작거나 9999보다 큽니다.

또는

month가 1보다 작거나 12보다 큽니다.

또는

day 가 1보다 작거나 month의 일 수보다 큽니다.

예제

다음 예제에서는 생성자를 사용하여 DateTime(Int32, Int32, Int32) 값을 인스턴스화합니다 DateTime . 또한 이 오버로드는 시간 구성 요소가 자정(또는 0:00)과 같은 값을 만드는 DateTime 것을 보여 줍니다.

DateTime date1 = new DateTime(2010, 8, 18);
Console.WriteLine(date1.ToString());
// The example displays the following output:
//      8/18/2010 12:00:00 AM
let date1 = DateTime(2010, 8, 18)
printfn $"{date1}"

// The example displays the following output:
//      8/18/2010 12:00:00 AM
Dim date1 As New Date(2010, 8, 18)
Console.WriteLine(date1.ToString())
' The example displays the following output:
'      8/18/2010 12:00:00 AM

설명

이 생성자는 , monthdayyear그레고리오력의 1년, 월 및 일로 해석합니다. 다른 달력에서 DateTime 연도, 월 및 일을 사용하여 값을 인스턴스화하려면 생성자를 호출합니다 DateTime(Int32, Int32, Int32, Calendar) .

결과 DateTime 날짜의 시간은 자정(00:00:00)입니다. Kind 속성이 DateTimeKind.Unspecified으로 초기화됩니다.

적용 대상

DateTime(DateOnly, TimeOnly, DateTimeKind)

지정된 및 에 대한 구조체의 DateTime 새 instance 초기화하고 TimeOnly 지정된 DateTimeKind를 준수 DateOnly 합니다.

public:
 DateTime(DateOnly date, TimeOnly time, DateTimeKind kind);
public DateTime (DateOnly date, TimeOnly time, DateTimeKind kind);
new DateTime : DateOnly * TimeOnly * DateTimeKind -> DateTime
Public Sub New (date As DateOnly, time As TimeOnly, kind As DateTimeKind)

매개 변수

date
DateOnly

날짜 부분입니다.

time
TimeOnly

시간 파트입니다.

kind
DateTimeKind

현지 시간, UTC(협정 세계시) 또는 둘 다 지정할지 여부를 datetime 나타내는 열거형 값 중 하나입니다.

적용 대상

DateTime(Int64, DateTimeKind)

DateTime 구조체의 새 인스턴스를 지정된 틱 수 및 UTC(협정 세계시) 또는 현지 시간으로 초기화합니다.

public:
 DateTime(long ticks, DateTimeKind kind);
public DateTime (long ticks, DateTimeKind kind);
new DateTime : int64 * DateTimeKind -> DateTime
Public Sub New (ticks As Long, kind As DateTimeKind)

매개 변수

ticks
Int64

그레고리오력에서 0001년 1월 1일 00:00:00.000부터 경과한 100나노초 간격의 수로 표현한 날짜와 시간입니다.

kind
DateTimeKind

ticks가 현지 시간 또는 UTC(협정 세계시)를 지정하는지, 아니면 둘 다 지정하지 않는지를 나타내는 열거형 값 중 하나입니다.

예외

kindDateTimeKind 값 중 하나가 아닙니다.

설명

날짜 및 시간 데이터 또는 제한 된 수준의 표준 시간대는 이식성 인식의 중요 한 애플리케이션을 사용할 수 있습니다 해당 DateTimeOffset 생성자입니다.

적용 대상

DateTime(DateOnly, TimeOnly)

구조체의 새 instance DateTime 지정된 DateOnlyTimeOnly로 초기화합니다. 새 instance 종류가 Unspecified 있습니다.

public:
 DateTime(DateOnly date, TimeOnly time);
public DateTime (DateOnly date, TimeOnly time);
new DateTime : DateOnly * TimeOnly -> DateTime
Public Sub New (date As DateOnly, time As TimeOnly)

매개 변수

date
DateOnly

날짜 부분입니다.

time
TimeOnly

시간 파트입니다.

적용 대상

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

DateTime 구조체의 새 인스턴스를 지정된 달력에서 지정된 연도, 월, 일, 시, 분 및 초로 초기화합니다.

public:
 DateTime(int year, int month, int day, int hour, int minute, int second, System::Globalization::Calendar ^ calendar);
public DateTime (int year, int month, int day, int hour, int minute, int second, System.Globalization.Calendar calendar);
new DateTime : int * int * int * int * int * int * System.Globalization.Calendar -> DateTime
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, calendar As Calendar)

매개 변수

year
Int32

연도(1부터 calendar에 있는 연수까지)

month
Int32

월(1부터 calendar에 있는 월수까지)

day
Int32

일(1부터 month에 있는 일수까지)

hour
Int32

시(0부터 23까지)

minute
Int32

분(0부터 59까지)

second
Int32

초(0부터 59까지)

calendar
Calendar

year, monthday를 해석하는 데 사용되는 달력입니다.

예외

calendar이(가) null인 경우

yearcalendar에서 지원되는 범위에 없습니다.

또는

month가 1보다 작거나 calendar의 개월 수보다 큽니다.

또는

day 가 1보다 작거나 month의 일 수보다 큽니다.

또는

hour가 0보다 작거나 23보다 큽니다.

또는

minute가 0보다 작거나 59보다 큽니다.

또는

second가 0보다 작거나 59보다 큽니다.

예제

다음 예제에서는 생성자를 두 번 호출 DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Calendar) 하여 두 DateTime 값을 인스턴스화합니다. 첫 번째 호출은 개체를 DateTime 사용하여 PersianCalendar 값을 인스턴스화합니다. 페르시아 달력은 문화권의 기본 달력으로 지정할 수 없으므로 페르시아 달력에 날짜를 표시하려면 , PersianCalendar.GetDayOfMonthPersianCalendar.GetYear 메서드에 대한 개별 호출이 PersianCalendar.GetMonth필요합니다. 생성자에 대한 두 번째 호출은 개체를 DateTime 사용하여 HijriCalendar 값을 인스턴스화합니다. 이 예제에서는 현재 문화권을 아랍어(시리아)로 변경하고 현재 문화권의 기본 달력을 Hijri 달력으로 변경합니다. Hijri는 현재 문화권의 기본 달력이므로 메서드는 Console.WriteLine 이를 사용하여 날짜의 서식을 지정합니다. 이전 현재 문화권(이 경우 영어(미국))이 복원되면 Console.WriteLine 메서드는 현재 문화권의 기본 그레고리오력 을 사용하여 날짜 서식을 지정합니다.

using System;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Threading;

public class Example
{
   public static void Main()
   {
      Console.WriteLine("Using the Persian Calendar:");
      PersianCalendar persian = new PersianCalendar();
      DateTime date1 = new DateTime(1389, 5, 27, 16, 32, 0, persian);
      Console.WriteLine(date1.ToString());
      Console.WriteLine("{0}/{1}/{2} {3}{6}{4:D2}{6}{5:D2}\n",
                                       persian.GetMonth(date1),
                                       persian.GetDayOfMonth(date1),
                                       persian.GetYear(date1),
                                       persian.GetHour(date1),
                                       persian.GetMinute(date1),
                                       persian.GetSecond(date1),
                                       DateTimeFormatInfo.CurrentInfo.TimeSeparator);

      Console.WriteLine("Using the Hijri Calendar:");
      // Get current culture so it can later be restored.
      CultureInfo dftCulture = Thread.CurrentThread.CurrentCulture;

      // Define Hijri calendar.
      HijriCalendar hijri = new HijriCalendar();
      // Make ar-SY the current culture and Hijri the current calendar.
      Thread.CurrentThread.CurrentCulture = new CultureInfo("ar-SY");
      CultureInfo current = CultureInfo.CurrentCulture;
      current.DateTimeFormat.Calendar = hijri;
      string dFormat = current.DateTimeFormat.ShortDatePattern;
      // Ensure year is displayed as four digits.
      dFormat = Regex.Replace(dFormat, "/yy$", "/yyyy");
      current.DateTimeFormat.ShortDatePattern = dFormat;
      DateTime date2 = new DateTime(1431, 9, 9, 16, 32, 18, hijri);
      Console.WriteLine("{0} culture using the {1} calendar: {2:g}", current,
                        GetCalendarName(hijri), date2);

      // Restore previous culture.
      Thread.CurrentThread.CurrentCulture = dftCulture;
      Console.WriteLine("{0} culture using the {1} calendar: {2:g}",
                        CultureInfo.CurrentCulture,
                        GetCalendarName(CultureInfo.CurrentCulture.Calendar),
                        date2);
   }

   private static string GetCalendarName(Calendar cal)
   {
      return Regex.Match(cal.ToString(), "\\.(\\w+)Calendar").Groups[1].Value;
   }
}
// The example displays the following output:
//       Using the Persian Calendar:
//       8/18/2010 4:32:00 PM
//       5/27/1389 16:32:00
//
//       Using the Hijri Calendar:
//       ar-SY culture using the Hijri calendar: 09/09/1431 04:32 م
//       en-US culture using the Gregorian calendar: 8/18/2010 4:32 PM
open System
open System.Globalization
open System.Text.RegularExpressions
open System.Threading

let getCalendarName (cal: Calendar) =
    Regex.Match(string cal, "\\.(\\w+)Calendar").Groups[1].Value

printfn "Using the Persian Calendar:"
let persian = PersianCalendar()
let date1 = DateTime(1389, 5, 27, 16, 32, 0, persian)
printfn $"{date1}"
let sep = DateTimeFormatInfo.CurrentInfo.TimeSeparator
printfn $"{persian.GetMonth date1}/{persian.GetDayOfMonth date1}/{persian.GetYear date1} {persian.GetHour date1}{sep}%02i{persian.GetMinute date1}{sep}%02i{persian.GetSecond date1}\n"

printfn "Using the Hijri Calendar:"

// Get current culture so it can later be restored.
let dftCulture = Thread.CurrentThread.CurrentCulture

// Define Hijri calendar.
let hijri = HijriCalendar()

// Make ar-SY the current culture and Hijri the current calendar.
Thread.CurrentThread.CurrentCulture <- CultureInfo "ar-SY"
let current = CultureInfo.CurrentCulture
current.DateTimeFormat.Calendar <- hijri
let dFormat = 
    let dFormat = current.DateTimeFormat.ShortDatePattern
    // Ensure year is displayed as four digits.
    Regex.Replace(dFormat, "/yy$", "/yyyy")

current.DateTimeFormat.ShortDatePattern <- dFormat
let date2 = DateTime(1431, 9, 9, 16, 32, 18, hijri)
printfn $"{current} culture using the {getCalendarName hijri} calendar: {date2:g}"

// Restore previous culture.
Thread.CurrentThread.CurrentCulture <- dftCulture
printfn $"{CultureInfo.CurrentCulture} culture using the {getCalendarName CultureInfo.CurrentCulture.Calendar} calendar: {date2:g}"


// The example displays the following output:
//       Using the Persian Calendar:
//       8/18/2010 4:32:00 PM
//       5/27/1389 16:32:00
//
//       Using the Hijri Calendar:
//       ar-SY culture using the Hijri calendar: 09/09/1431 04:32 م
//       en-US culture using the Gregorian calendar: 8/18/2010 4:32 PM
Imports System.Globalization
Imports System.Text.RegularExpressions
Imports System.Threading

Module Example
   Public Sub Main()
      Console.WriteLine("Using the Persian Calendar:")
      Dim persian As New PersianCalendar()
      Dim date1 As New Date(1389, 5, 27, 16, 32, 0, persian)
      Console.WriteLine(date1.ToString())
      Console.WriteLine("{0}/{1}/{2} {3}{6}{4:D2}{6}{5:D2}", persian.GetMonth(date1), _
                                       persian.GetDayOfMonth(date1), _
                                       persian.GetYear(date1), _
                                       persian.GetHour(date1), _
                                       persian.GetMinute(date1), _
                                       persian.GetSecond(date1), _
                                       DateTimeFormatInfo.CurrentInfo.TimeSeparator)
      Console.WriteLine()
      
      Console.WriteLine("Using the Hijri Calendar:")
      ' Get current culture so it can later be restored.
      Dim dftCulture As CultureInfo = Thread.CurrentThread.CurrentCulture
      
      ' Define Hijri calendar.
      Dim hijri As New HijriCalendar()
      ' Make ar-SY the current culture and Hijri the current calendar.
      Thread.CurrentThread.CurrentCulture = New CultureInfo("ar-SY")
      Dim current As CultureInfo = CultureInfo.CurrentCulture
      current.DateTimeFormat.Calendar = hijri
      Dim dFormat As String = current.DateTimeFormat.ShortDatePattern
      ' Ensure year is displayed as four digits.
      dFormat = Regex.Replace(dFormat, "/yy$", "/yyyy")
      current.DateTimeFormat.ShortDatePattern = dFormat
      Dim date2 As New Date(1431, 9, 9, 16, 32, 0, hijri)
      Console.WriteLine("{0} culture using the {1} calendar: {2:g}", current, _
                        GetCalendarName(hijri), date2) 

      ' Restore previous culture.
      Thread.CurrentThread.CurrentCulture = dftCulture
      Console.WriteLine("{0} culture using the {1} calendar: {2:g}", _
                        CultureInfo.CurrentCulture, _
                        GetCalendarName(CultureInfo.CurrentCulture.Calendar), _
                        date2) 
   End Sub
   
   Private Function GetCalendarName(cal As Calendar) As String
      Return Regex.Match(cal.ToString(), "\.(\w+)Calendar").Groups(1).Value
   End Function
End Module
' The example displays the following output:
'       Using the Persian Calendar:
'       8/18/2010 4:32:00 PM
'       5/27/1389 16:32:00
'       
'       Using the Hijri Calendar:
'       ar-SY culture using the Hijri calendar: 09/09/1431 04:32 م
'       en-US culture using the Gregorian calendar: 8/18/2010 4:32 PM

설명

Kind 속성이 Unspecified으로 초기화됩니다.

, monthday 에 허용되는 year값은 에 calendar따라 달라집니다. 를 사용하여 calendar지정된 날짜와 시간을 표현할 수 없는 경우 예외가 throw됩니다.

중요

일본어 달력의 시대는 천황 통치 기간을 기준으로 하므로 변경되어야 합니다. 예를 들어 2019년 5월 1일은 JapaneseCalendarJapaneseLunisolarCalendar에서 레이와 시대의 시작을 나타냅니다. 이러한 시대 변경 내용은 해당 달력을 사용하는 모든 애플리케이션에 영향을 줍니다. 자세한 내용과 애플리케이션이 영향을 받는지 여부를 확인하려면 .NET의 일본 달력에서 새 시대 처리를 참조하세요. Windows 시스템에서 애플리케이션을 테스트하여 시대 변화에 대한 준비 상태를 확인하는 방법에 대한 자세한 내용은 일본 시대 변화를 위한 애플리케이션 준비를 참조하세요. 여러 시대가 있는 달력을 지원하는 .NET의 기능과 여러 시대를 지원하는 달력으로 작업할 때 모범 사례는 시대 작업을 참조하세요.

네임스페이 System.Globalization 스는 및 JulianCalendar을 비롯한 GregorianCalendar 여러 일정을 제공합니다.

추가 정보

적용 대상