DateTimeOffset 생성자
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
구조체의 새 인스턴스를 초기화합니다 DateTimeOffset .
오버로드
DateTimeOffset(DateTime)
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
지정된 DateTime 값을 사용하여 구조체의 DateTimeOffset 새 인스턴스를 초기화합니다.
public:
DateTimeOffset(DateTime dateTime);
public DateTimeOffset(DateTime dateTime);
new DateTimeOffset : DateTime -> DateTimeOffset
Public Sub New (dateTime As DateTime)
매개 변수
- dateTime
- DateTime
날짜 및 시간입니다.
예외
오프셋을 적용한 결과 UTC(협정 세계시) 날짜 및 시간이 DateTimeOffset.MinValue보다 깁니다.
-또는-
오프셋을 적용한 결과 UTC 날짜 및 시간은 DateTimeOffset.MaxValue보다 늦습니다.
예제
다음 예제에서는 매개 변수의 DateTime.Kind 속성 dateTime 값이 이 생성자가 반환하는 날짜 및 시간 값에 미치는 영향을 보여 줍니다.
DateTime localNow = DateTime.Now;
DateTimeOffset localOffset = new DateTimeOffset(localNow);
Console.WriteLine(localOffset.ToString());
DateTime utcNow = DateTime.UtcNow;
DateTimeOffset utcOffset = new DateTimeOffset(utcNow);
Console.WriteLine(utcOffset.ToString());
DateTime unspecifiedNow = DateTime.SpecifyKind(DateTime.Now,
DateTimeKind.Unspecified);
DateTimeOffset unspecifiedOffset = new DateTimeOffset(unspecifiedNow);
Console.WriteLine(unspecifiedOffset.ToString());
//
// The code produces the following output if run on Feb. 23, 2007, on
// a system 8 hours earlier than UTC:
// 2/23/2007 4:21:58 PM -08:00
// 2/24/2007 12:21:58 AM +00:00
// 2/23/2007 4:21:58 PM -08:00
let localNow = DateTime.Now
let localOffset = DateTimeOffset localNow
printfn $"{localOffset}"
let utcNow = DateTime.UtcNow
let utcOffset = DateTimeOffset utcNow
printfn "{utcOffset}"
let unspecifiedNow = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified)
let unspecifiedOffset = DateTimeOffset unspecifiedNow
printfn $"{unspecifiedOffset}"
// The code produces the following output if run on Feb. 23, 2007, on
// a system 8 hours earlier than UTC:
// 2/23/2007 4:21:58 PM -08:00
// 2/24/2007 12:21:58 AM +00:00
// 2/23/2007 4:21:58 PM -08:00
Dim localNow As Date = Date.Now
Dim localOffset As New DateTimeOffset(localNow)
Console.WriteLine(localOffset.ToString())
Dim utcNow As Date = Date.UtcNow
Dim utcOffset As New DateTimeOffset(utcNow)
Console.WriteLine(utcOffset.ToString())
Dim unspecifiedNow As Date = Date.SpecifyKind(Date.Now, _
DateTimeKind.Unspecified)
Dim unspecifiedOffset As New DateTimeOffset(unspecifiedNow)
Console.WriteLine(unspecifiedOffset.ToString())
'
' The code produces the following output if run on Feb. 23, 2007, on
' a system 8 hours earlier than UTC:
' 2/23/2007 4:21:58 PM -08:00
' 2/24/2007 12:21:58 AM +00:00
' 2/23/2007 4:21:58 PM -08:00
설명
이 생성자의 동작은 매개 변수의 DateTime.Kind 속성 값에 dateTime 따라 달라집니다.
값 DateTime.Kind 이면 DateTimeDateTimeKind.Utc새 인스턴스의 속성이 같게
dateTime설정되고 Offset 속성이 같게 Zero설정됩니다.값 DateTime.Kind 이 is DateTimeKind.Local 또는 DateTimeKind.Unspecified이 DateTime 면 새 인스턴스의 속성이 같게
dateTime설정되고 Offset 속성이 로컬 시스템의 현재 표준 시간대 오프셋과 동일하게 설정됩니다.
추가 정보
적용 대상
DateTimeOffset(DateTime, TimeSpan)
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
지정된 값 및 offset.을 사용하여 구조체의 DateTimeOffset 새 인스턴스를 DateTime 초기화합니다.
public:
DateTimeOffset(DateTime dateTime, TimeSpan offset);
public DateTimeOffset(DateTime dateTime, TimeSpan offset);
new DateTimeOffset : DateTime * TimeSpan -> DateTimeOffset
Public Sub New (dateTime As DateTime, offset As TimeSpan)
매개 변수
- dateTime
- DateTime
날짜 및 시간입니다.
- offset
- TimeSpan
UTC(협정 세계시)의 시간 오프셋입니다.
예외
dateTime.Kind 같 Utc 고 0이 offset 아닙니다.
-또는-
dateTime.Kind 는 Local 시스템의 현지 표준 시간대 오프셋과 offset 같지 않습니다.
-또는-
offset 은 전체 시간(분)에 지정되지 않습니다.
offset 가 -14 시간보다 작거나 14시간보다 큽다.
-또는-
UtcDateTime 가 DateTimeOffset.MinValue보다 작거나 DateTimeOffset.MaxValue보다 큽니다.
예제
다음 예제에서는 날짜 및 시간과 해당 표준 시간대를 미리 알 수 없는 경우 현지 표준 시간대의 오프셋을 사용하여 개체를 초기화하는 DateTimeOffset 방법을 보여 드립니다.
DateTime localTime = new DateTime(2007, 07, 12, 06, 32, 00);
DateTimeOffset dateAndOffset = new DateTimeOffset(localTime,
TimeZoneInfo.Local.GetUtcOffset(localTime));
Console.WriteLine(dateAndOffset);
// The code produces the following output:
// 7/12/2007 6:32:00 AM -07:00
let localTime = DateTime(2007, 07, 12, 06, 32, 00)
let dateAndOffset = DateTimeOffset(localTime, TimeZoneInfo.Local.GetUtcOffset localTime)
printfn $"{dateAndOffset}"
// The code produces the following output:
// 7/12/2007 6:32:00 AM -07:00
Dim localTime As Date = #07/12/2007 6:32AM#
Dim dateAndOffset As New DateTimeOffset(localTime, _
TimeZoneInfo.Local.GetUtcOffset(localTime))
Console.WriteLine(dateAndOffset)
' The code produces the following output:
' 7/12/2007 6:32:00 AM -07:00
설명
이 생성자의 동작은 매개 변수의 속성 dateTime 값에 Kind 부분적으로 따라 달라집니다.
값 Kind 이면 DateTimeKind.Utc매개 변수 값이
offset0 ArgumentException 이거나 throw되어야 합니다.값 Kind 이면 매개 변수 값
offset은 DateTimeKind.Local특정 날짜에 대한 UTC(협정 세계시)의 현지 표준 시간대 오프셋과 같아야 ArgumentException 합니다.값 Kind 이면 DateTimeKind.Unspecified매개 변수에
offset유효한 값이 있을 수 있습니다.
추가 정보
적용 대상
DateTimeOffset(Int64, TimeSpan)
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
지정된 수 ticks 및 을 사용하여 구조체의 DateTimeOffset 새 인스턴스를 초기화합니다offset.
public:
DateTimeOffset(long ticks, TimeSpan offset);
public DateTimeOffset(long ticks, TimeSpan offset);
new DateTimeOffset : int64 * TimeSpan -> DateTimeOffset
Public Sub New (ticks As Long, offset As TimeSpan)
매개 변수
- ticks
- Int64
0001년 1월 1일 자정 12:00:00 이후 경과된 100나노초 간격의 수로 표현된 날짜 및 시간입니다.
- offset
- TimeSpan
UTC(협정 세계시)의 시간 오프셋입니다.
예외
offset 은 전체 시간(분)에 지정되지 않습니다.
속성 UtcDateTime 이 DateTimeOffset.MinValue 보다 이전이거나 DateTimeOffset.MaxValue보다 늦습니다.
-또는-
ticks가 .보다 DateTimeOffset.MinValue.Ticks 작거나 큼 DateTimeOffset.MaxValue.Ticks
-또는-
offset 가 -14 시간보다 작거나 14시간보다 큽다.
예제
다음은 오프셋이 -5인 임의의 날짜(이 경우 2007년 7월 16일 오후 1시 32분)의 틱 수를 사용하여 개체를 초기화하는 DateTimeOffset 예제입니다.
DateTime dateWithoutOffset = new DateTime(2007, 7, 16, 13, 32, 00);
DateTimeOffset timeFromTicks = new DateTimeOffset(dateWithoutOffset.Ticks,
new TimeSpan(-5, 0, 0));
Console.WriteLine(timeFromTicks.ToString());
// The code produces the following output:
// 7/16/2007 1:32:00 PM -05:00
let dateWithoutOffset = DateTime(2007, 7, 16, 13, 32, 00)
let timeFromTicks = DateTimeOffset(dateWithoutOffset.Ticks, TimeSpan(-5, 0, 0))
printfn $"{timeFromTicks}"
// The code produces the following output:
// 7/16/2007 1:32:00 PM -05:00
Dim dateWithoutOffset As Date = #07/16/2007 1:32PM#
Dim timeFromTicks As New DateTimeOffset(datewithoutOffset.Ticks, _
New TimeSpan(-5, 0, 0))
Console.WriteLine(timeFromTicks.ToString())
' The code produces the following output:
' 7/16/2007 1:32:00 PM -05:00
설명
일반적으로 생성자를 호출 DateTimeOffset 하여 현지 시간으로 값을 인스턴스화하고 현지 표준 시간대 이외의 오프셋을 인스턴스화 DateTimeOffset 하려고 하면 해당 값이 throw됩니다 ArgumentException. 생성자의 이 오버로드를 DateTimeOffset 사용하여 이 제한 사항을 해결할 수 있습니다. 다음 예제에서는 현지 시간의 틱 수를 사용하여 오프셋이 반드시 현지 시간의 값을 나타내지 않는 값을 인스턴스화 DateTimeOffset 합니다.
DateTime localTime = DateTime.Now;
DateTimeOffset nonLocalDateWithOffset = new DateTimeOffset(localTime.Ticks,
new TimeSpan(2, 0, 0));
Console.WriteLine(nonLocalDateWithOffset);
//
// The code produces the following output if run on Feb. 23, 2007:
// 2/23/2007 4:37:50 PM +02:00
let localTime = DateTime.Now
let nonLocalDateWithOffset = DateTimeOffset(localTime.Ticks, TimeSpan(2, 0, 0))
printfn $"{nonLocalDateWithOffset}"
// The code produces the following output if run on Feb. 23, 2007:
// 2/23/2007 4:37:50 PM +02:00
Dim localTime As Date = Date.Now
Dim nonLocalDateWithOffset As New DateTimeOffset(localTime.Ticks, _
New TimeSpan(2, 0, 0))
Console.WriteLine(nonLocalDateWithOffset)
'
' The code produces the following output if run on Feb. 23, 2007:
' 2/23/2007 4:37:50 PM +02:00
추가 정보
적용 대상
DateTimeOffset(DateOnly, TimeOnly, TimeSpan)
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
지정된 및 를 사용하여 구조체의 DateTimeOffset 새 인스턴스를 datetime초기화합니다offset.
public:
DateTimeOffset(DateOnly date, TimeOnly time, TimeSpan offset);
public DateTimeOffset(DateOnly date, TimeOnly time, TimeSpan offset);
new DateTimeOffset : DateOnly * TimeOnly * TimeSpan -> DateTimeOffset
Public Sub New (date As DateOnly, time As TimeOnly, offset As TimeSpan)
매개 변수
- date
- DateOnly
날짜 부분입니다.
- time
- TimeOnly
시간 부분입니다.
- offset
- TimeSpan
UTC(협정 세계시)의 시간 오프셋입니다.
적용 대상
DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
지정된 , , secondminutemonthdayhour, 및 offset를 사용하여 구조체의 DateTimeOffset 새 인스턴스를 초기화합니다.year
public:
DateTimeOffset(int year, int month, int day, int hour, int minute, int second, TimeSpan offset);
public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, TimeSpan offset);
new DateTimeOffset : int * int * int * int * int * int * TimeSpan -> DateTimeOffset
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, offset As TimeSpan)
매개 변수
- year
- Int32
연도(1~9999).
- month
- Int32
월(1~12)입니다.
- day
- Int32
일(1부터 일 수까지)입니다 month.
- hour
- Int32
시간(0~23)입니다.
- minute
- Int32
분(0~59)입니다.
- second
- Int32
초(0~59)입니다.
- offset
- TimeSpan
UTC(협정 세계시)의 시간 오프셋입니다.
예외
offset 는 전체 분을 나타내지 않습니다.
year 가 1보다 작거나 9999보다 큰 경우
-또는-
month 가 1보다 작거나 12보다 큰 경우
-또는-
day가 1보다 작거나 .의 일 수보다 큰 경우 month
-또는-
hour 가 0보다 작거나 23보다 큽니다.
-또는-
minute 가 0보다 작거나 59보다 큰 경우
-또는-
second 가 0보다 작거나 59보다 큰 경우
-또는-
offset 가 -14 시간보다 작거나 14시간보다 큽다.
-또는-
속성 UtcDateTime 이 DateTimeOffset.MinValue 보다 이전이거나 DateTimeOffset.MaxValue보다 늦습니다.
예제
다음은 생성자 오버로드를 DateTimeOffset 사용하여 개체를 DateTimeOffset.DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan) 인스턴스화하는 예제입니다.
DateTime specificDate = new DateTime(2008, 5, 1, 06, 32, 00);
DateTimeOffset offsetDate = new DateTimeOffset(specificDate.Year,
specificDate.Month,
specificDate.Day,
specificDate.Hour,
specificDate.Minute,
specificDate.Second,
new TimeSpan(-5, 0, 0));
Console.WriteLine("Current time: {0}", offsetDate);
Console.WriteLine("Corresponding UTC time: {0}", offsetDate.UtcDateTime);
// The code produces the following output:
// Current time: 5/1/2008 6:32:00 AM -05:00
// Corresponding UTC time: 5/1/2008 11:32:00 AM
let specificDate = DateTime(2008, 5, 1, 06, 32, 00)
let offsetDate = DateTimeOffset(specificDate.Year,
specificDate.Month,
specificDate.Day,
specificDate.Hour,
specificDate.Minute,
specificDate.Second,
TimeSpan(-5, 0, 0))
printfn $"Current time: {offsetDate}"
printfn $"Corresponding UTC time: {offsetDate.UtcDateTime}"
// The code produces the following output:
// Current time: 5/1/2008 6:32:00 AM -05:00
// Corresponding UTC time: 5/1/2008 11:32:00 AM
Dim specificDate As Date = #5/1/2008 6:32AM#
Dim offsetDate As New DateTimeOffset(specificDate.Year, _
specificDate.Month, _
specificDate.Day, _
specificDate.Hour, _
specificDate.Minute, _
specificDate.Second, _
New TimeSpan(-5, 0, 0))
Console.WriteLine("Current time: {0}", offsetDate)
Console.WriteLine("Corresponding UTC time: {0}", offsetDate.UtcDateTime)
' The code produces the following output:
' Current time: 5/1/2008 6:32:00 AM -05:00
' Corresponding UTC time: 5/1/2008 11:32:00 AM
설명
이 생성자는 그레고리오력에서 1년, 월 및 일로 해석 yearmonthday 합니다. 다른 달력에서 DateTimeOffset 연도, 월 및 일을 사용하여 값을 인스턴스화하려면 생성자를 호출 DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) 합니다.
추가 정보
적용 대상
DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
지정된 , ,month, minutemillisecondsecondhourday, 및 offset를 사용하여 구조체의 DateTimeOffset 새 인스턴스를 초기화합니다.year
public:
DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, TimeSpan offset);
public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, TimeSpan offset);
new DateTimeOffset : int * int * int * int * int * int * int * TimeSpan -> DateTimeOffset
Public Sub New (year As Integer, month As Integer, day As Integer, hour As Integer, minute As Integer, second As Integer, millisecond As Integer, offset As TimeSpan)
매개 변수
- 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)입니다.
- offset
- TimeSpan
UTC(협정 세계시)의 시간 오프셋입니다.
예외
offset 는 전체 분을 나타내지 않습니다.
year 가 1보다 작거나 9999보다 큰 경우
-또는-
month 가 1보다 작거나 12보다 큰 경우
-또는-
day가 1보다 작거나 .의 일 수보다 큰 경우 month
-또는-
hour 가 0보다 작거나 23보다 큽니다.
-또는-
minute 가 0보다 작거나 59보다 큰 경우
-또는-
second 가 0보다 작거나 59보다 큰 경우
-또는-
millisecond 가 0보다 작거나 999보다 큰 경우
-또는-
offset 가 -14 미만이거나 14보다 큰 경우
-또는-
속성 UtcDateTime 이 DateTimeOffset.MinValue 보다 이전이거나 DateTimeOffset.MaxValue보다 늦습니다.
예제
다음은 생성자 오버로드를 DateTimeOffset 사용하여 개체를 DateTimeOffset.DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan) 인스턴스화하는 예제입니다.
string fmt = "dd MMM yyyy HH:mm:ss";
DateTime thisDate = new DateTime(2007, 06, 12, 19, 00, 14, 16);
DateTimeOffset offsetDate = new DateTimeOffset(thisDate.Year,
thisDate.Month,
thisDate.Day,
thisDate.Hour,
thisDate.Minute,
thisDate.Second,
thisDate.Millisecond,
new TimeSpan(2, 0, 0));
Console.WriteLine("Current time: {0}:{1}", offsetDate.ToString(fmt), offsetDate.Millisecond);
// The code produces the following output:
// Current time: 12 Jun 2007 19:00:14:16
let fmt = "dd MMM yyyy HH:mm:ss"
let thisDate = DateTime(2007, 06, 12, 19, 00, 14, 16)
let offsetDate = DateTimeOffset(thisDate.Year,
thisDate.Month,
thisDate.Day,
thisDate.Hour,
thisDate.Minute,
thisDate.Second,
thisDate.Millisecond,
TimeSpan(2, 0, 0))
printfn $"Current time: {offsetDate.ToString fmt}:{offsetDate.Millisecond}"
// The code produces the following output:
// Current time: 12 Jun 2007 19:00:14:16
Dim fmt As String = "dd MMM yyyy HH:mm:ss"
Dim thisDate As DateTime = New Date(2007, 06, 12, 19, 00, 14, 16)
Dim offsetDate As New DateTimeOffset(thisDate.Year, _
thisDate.Month, _
thisDate.Day, _
thisDate.Hour, _
thisDate.Minute, _
thisDate.Second, _
thisDate.Millisecond, _
New TimeSpan(2, 0, 0))
Console.WriteLine("Current time: {0}:{1}", offsetDate.ToString(fmt), _
offsetDate.Millisecond)
' The code produces the following output:
' Current time: 12 Jun 2007 19:00:14:16
설명
이 생성자는 그레고리오력에서 1년, 월 및 일로 해석 yearmonthday 합니다. 다른 달력에서 DateTimeOffset 연도, 월 및 일을 사용하여 값을 인스턴스화하려면 생성자를 호출 DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) 합니다.
추가 정보
적용 대상
DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan)
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
지정된 , ,, hoursecondmonthcalendardaymillisecondminute및 offset를 사용하여 구조체의 DateTimeOffset 새 인스턴스를 초기화합니다.year
public:
DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, System::Globalization::Calendar ^ calendar, TimeSpan offset);
public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, System.Globalization.Calendar calendar, TimeSpan offset);
new DateTimeOffset : int * int * int * int * int * int * int * System.Globalization.Calendar * TimeSpan -> DateTimeOffset
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, offset As TimeSpan)
매개 변수
- year
- Int32
연도입니다.
- month
- Int32
월(1~12)입니다.
- day
- Int32
일(1부터 일 수까지)입니다 month.
- hour
- Int32
시간(0~23)입니다.
- minute
- Int32
분(0~59)입니다.
- second
- Int32
초(0~59)입니다.
- millisecond
- Int32
밀리초(0~999)입니다.
- calendar
- Calendar
해석yearmonth하는 데 사용되는 달력 및 day.
- offset
- TimeSpan
UTC(협정 세계시)의 시간 오프셋입니다.
예외
offset 는 전체 분을 나타내지 않습니다.
calendar는 null일 수 없습니다.
year가 매개 변수 MinSupportedDateTime.Year 보다 calendar 작거나 MaxSupportedDateTime.Year.
-또는-
month 가 .에 있는 yearcalendar월 수보다 작거나 큰 경우
-또는-
day가 1보다 작거나 .의 일 수보다 큰 경우 month
-또는-
hour 가 0보다 작거나 23보다 큽니다.
-또는-
minute 가 0보다 작거나 59보다 큰 경우
-또는-
second 가 0보다 작거나 59보다 큰 경우
-또는-
millisecond 가 0보다 작거나 999보다 큰 경우
-또는-
offset 가 -14 시간보다 작거나 14시간보다 큽다.
-또는-
, month및 day 매개 변수를 year날짜 및 시간 값으로 나타낼 수 없습니다.
-또는-
속성 UtcDateTime 이 DateTimeOffset.MinValue 보다 이전이거나 DateTimeOffset.MaxValue보다 늦습니다.
예제
다음 예제에서는 클래스와 클래스의 인스턴스를 HijriCalendar 모두 HebrewCalendar 사용하여 값을 인스턴스화합니다DateTimeOffset. 그런 다음 해당 달력과 그레고리오력을 사용하여 해당 날짜가 콘솔에 표시됩니다.
CultureInfo fmt;
int year;
Calendar cal;
DateTimeOffset dateInCal;
// Instantiate DateTimeOffset with Hebrew calendar
year = 5770;
cal = new HebrewCalendar();
fmt = new CultureInfo("he-IL");
fmt.DateTimeFormat.Calendar = cal;
dateInCal = new DateTimeOffset(year, 7, 12,
15, 30, 0, 0,
cal,
new TimeSpan(2, 0, 0));
// Display the date in the Hebrew calendar
Console.WriteLine("Date in Hebrew Calendar: {0:g}",
dateInCal.ToString(fmt));
// Display the date in the Gregorian calendar
Console.WriteLine("Date in Gregorian Calendar: {0:g}", dateInCal);
Console.WriteLine();
// Instantiate DateTimeOffset with Hijri calendar
year = 1431;
cal = new HijriCalendar();
fmt = new CultureInfo("ar-SA");
fmt.DateTimeFormat.Calendar = cal;
dateInCal = new DateTimeOffset(year, 7, 12,
15, 30, 0, 0,
cal,
new TimeSpan(2, 0, 0));
// Display the date in the Hijri calendar
Console.WriteLine("Date in Hijri Calendar: {0:g}",
dateInCal.ToString(fmt));
// Display the date in the Gregorian calendar
Console.WriteLine("Date in Gregorian Calendar: {0:g}", dateInCal);
Console.WriteLine();
// Instantiate DateTimeOffset with Hebrew calendar
let year = 5770
let cal = HebrewCalendar()
let fmt = CultureInfo "he-IL"
fmt.DateTimeFormat.Calendar <- cal
let dateInCal = DateTimeOffset(year, 7, 12,
15, 30, 0, 0,
cal,
TimeSpan(2, 0, 0))
// Display the date in the Hebrew calendar
printfn $"Date in Hebrew Calendar: {dateInCal.ToString fmt:g}"
// Display the date in the Gregorian calendar
printfn $"Date in Gregorian Calendar: {dateInCal:g}\n"
// Instantiate DateTimeOffset with Hijri calendar
let year = 1431
let cal = HijriCalendar()
let fmt = CultureInfo "ar-SA"
fmt.DateTimeFormat.Calendar <- cal
let dateInCal = DateTimeOffset(year, 7, 12,
15, 30, 0, 0,
cal,
TimeSpan(2, 0, 0))
// Display the date in the Hijri calendar
printfn $"Date in Hijri Calendar: {dateInCal.ToString fmt:g}"
// Display the date in the Gregorian calendar
printfn $"Date in Gregorian Calendar: {dateInCal:g}\n"
Dim fmt As CultureInfo
Dim year As Integer
Dim cal As Calendar
Dim dateInCal As DateTimeOffset
' Instantiate DateTimeOffset with Hebrew calendar
year = 5770
cal = New HebrewCalendar()
fmt = New CultureInfo("he-IL")
fmt.DateTimeFormat.Calendar = cal
dateInCal = New DateTimeOffset(year, 7, 12, _
15, 30, 0, 0, _
cal, _
New TimeSpan(2, 0, 0))
' Display the date in the Hebrew calendar
Console.WriteLine("Date in Hebrew Calendar: {0:g}", _
dateInCal.ToString(fmt))
' Display the date in the Gregorian calendar
Console.WriteLine("Date in Gregorian Calendar: {0:g}", dateInCal)
Console.WriteLine()
' Instantiate DateTimeOffset with Hijri calendar
year = 1431
cal = New HijriCalendar()
fmt = New CultureInfo("ar-SA")
fmt.DateTimeFormat.Calendar = cal
dateInCal = New DateTimeOffset(year, 7, 12, _
15, 30, 0, 0, _
cal, _
New TimeSpan(2, 0, 0))
' Display the date in the Hijri calendar
Console.WriteLine("Date in Hijri Calendar: {0:g}", _
dateInCal.ToString(fmt))
' Display the date in the Gregorian calendar
Console.WriteLine("Date in Gregorian Calendar: {0:g}", dateInCal)
Console.WriteLine()
설명
, month, day, hour, minutesecond및 millisecond 매개 변수는 year모두 매개 변수로 지정된 달력에 표현된 calendar 값을 반영합니다. 이러한 값이 이 달력을 사용하여 표현할 수 없는 날짜와 시간을 형성하는 경우 예외가 throw됩니다.
중요하다
일본 달력의 시대는 황제의 통치를 기반으로하므로 변경 될 것으로 예상된다. 예를 들어, 2019년 5월 1일은 JapaneseCalendar과 JapaneseLunisolarCalendar에서 레이와 시대의 시작을 알렸다. 이러한 시대의 변화는 이러한 달력을 사용하는 모든 애플리케이션에 영향을 줍니다. 자세한 내용과 애플리케이션이 영향을 받는지 여부를 확인하려면 .NET의 일본 달력에서 새 시대 처리를 참조하세요. Windows 시스템에서 애플리케이션을 테스트하여 시대 변화에 대한 준비 상태를 확인하는 방법에 대한 자세한 내용은 일본 시대 변경을 위한 애플리케이션 준비를 참조하세요. 여러 연대가 있는 달력을 지원하는 .NET의 기능과 여러 연대를 지원하는 달력으로 작업할 때 모범 사례는 연대 작업(Working with era)을 참조하세요.
추가 정보
적용 대상
DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
지정된 , ,, hoursecondmonthmicroseconddaymillisecondminute및 offset를 사용하여 구조체의 DateTimeOffset 새 인스턴스를 초기화합니다.year
public:
DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond, TimeSpan offset);
public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond, TimeSpan offset);
new DateTimeOffset : int * int * int * int * int * int * int * int * TimeSpan -> DateTimeOffset
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, offset As TimeSpan)
매개 변수
- 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)입니다.
- offset
- TimeSpan
UTC(협정 세계시)의 시간 오프셋입니다.
예외
offset 는 전체 분을 나타내지 않습니다.
year 가 1보다 작거나 9999보다 큰 경우
-또는-
month 가 1보다 작거나 12보다 큰 경우
-또는-
day가 1보다 작거나 일 수보다 큰 경우 month
-또는-
hour 가 0보다 작거나 23보다 큰 경우
-또는-
minute 가 0보다 작거나 59보다 큰 경우
-또는-
second 가 0보다 작거나 59보다 큰 경우
-또는-
millisecond 가 0보다 작거나 999보다 큰 경우
-또는-
microsecond 가 0보다 작거나 999보다 큰 경우
설명
이 생성자는 그레고리오력에서 1년, 월, 일로 해석 yearmonthday 합니다. 다른 달력에서 DateTimeOffset 연도, 월 및 일을 사용하여 값을 인스턴스화하려면 생성자를 호출 DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) 합니다.
적용 대상
DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan)
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
- Source:
- DateTimeOffset.cs
지정된 , ,, , calendarminuteseconddayhourmillisecondmicrosecond, , month및 offset를 사용하여 구조체의 DateTimeOffset 새 인스턴스를 초기화합니다.year
public:
DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond, System::Globalization::Calendar ^ calendar, TimeSpan offset);
public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond, System.Globalization.Calendar calendar, TimeSpan offset);
new DateTimeOffset : int * int * int * int * int * int * int * int * System.Globalization.Calendar * TimeSpan -> DateTimeOffset
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, offset As TimeSpan)
매개 변수
- 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)입니다.
- calendar
- Calendar
해석yearmonth하는 데 사용되는 달력 및 day.
- offset
- TimeSpan
UTC(협정 세계시)의 시간 오프셋입니다.
예외
offset 는 전체 분을 나타내지 않습니다.
year 가 지원 calendar되는 범위에 없습니다.
-또는-
month가 1보다 작거나 월 수보다 큰 경우 calendar
-또는-
day가 1보다 작거나 일 수보다 큰 경우 month
-또는-
hour 가 0보다 작거나 23보다 큰 경우
-또는-
minute 가 0보다 작거나 59보다 큰 경우
-또는-
second 가 0보다 작거나 59보다 큰 경우
-또는-
millisecond 가 0보다 작거나 999보다 큰 경우
-또는-
microsecond 가 0보다 작거나 999보다 큰 경우
-또는-
offset 가 -14 시간보다 작거나 14시간보다 큽다.
-또는-
, month및 day 매개 변수를 year날짜 및 시간 값으로 나타낼 수 없습니다.
-또는-
속성이 UtcDateTime .보다 MinValue 이전 또는 이후 MaxValue입니다.
설명
이 생성자는 그레고리오력에서 1년, 월, 일로 해석 yearmonthday 합니다. 다른 달력에서 DateTimeOffset 연도, 월 및 일을 사용하여 값을 인스턴스화하려면 생성자를 호출 DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) 합니다.