DateTimeOffset コンストラクター

定義

DateTimeOffset 構造体の新しいインスタンスを初期化します。

オーバーロード

DateTimeOffset(DateTime)

DateTime 値を指定して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

DateTimeOffset(DateTime, TimeSpan)

指定された DateTime 値およびオフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

DateTimeOffset(Int64, TimeSpan)

指定されたタイマー刻みの数とオフセットで、DateTimeOffset 構造体の新しいインスタンスを初期化します。

DateTimeOffset(DateOnly, TimeOnly, TimeSpan)

指定した 、、および を使用して、 DateTimeOffset 構造体の新しいインスタンスを初期化しますoffsettimedate

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)

指定した年、月、日、時、分、秒、およびオフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)

指定した年、月、日、時、分、秒、ミリ秒、およびオフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan)

指定した暦の指定した年、月、日、時、分、秒、ミリ秒、およびオフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)

指定した monthyearsecondmicroseconddayhourminutemillisecond、および を使用して、 構造体の新しいインスタンスDateTimeOffsetoffset初期化します。

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan)

指定した monthyearsecondmicroseconddayhourminutemillisecond、および を使用して、 構造体の新しいインスタンスDateTimeOffsetoffset初期化します。

DateTimeOffset(DateTime)

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.KinddateTime値が、このコンストラクターによって返される日付と時刻の値にどのように影響するかを示しています。

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.KinddateTime値によって異なります。

こちらもご覧ください

適用対象

DateTimeOffset(DateTime, TimeSpan)

指定された DateTime 値およびオフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

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.KindUtc と等しく、offset は 0 と等しくありません。

- または -

dateTime.KindLocal と等しく、offset はシステムのローカル タイム ゾーンのオフセットと等しくありません。

- または -

offset が端数なしの分数で指定されていません。

offset が -14 時間より小さいか、14 時間を超えています。

- または -

UtcDateTimeDateTimeOffset.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

注釈

このコンストラクターの動作は、 パラメーターの プロパティの Kind 値に部分的に dateTime 依存します。

  • の値が の Kind 場合、 DateTimeKind.Utcパラメーターの値は offset 0 である必要があります。または が ArgumentException スローされます。

  • Kind 値が DateTimeKind.Localの場合、パラメーターの値は、その特定の offset 日付の協定世界時 (UTC) からのローカル タイム ゾーンのオフセットと等しい必要があります。または ArgumentException がスローされます。

  • の値が のKindDateTimeKind.Unspecified場合、パラメーターには任意のoffset有効な値を指定できます。

こちらもご覧ください

適用対象

DateTimeOffset(Int64, TimeSpan)

指定されたタイマー刻みの数とオフセットで、DateTimeOffset 構造体の新しいインスタンスを初期化します。

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 日午前 00:00:00 以降の経過時間 (100 ナノ秒単位) で表した値。

offset
TimeSpan

世界協定時刻 (UTC) からの時刻のオフセット。

例外

offset が端数なしの分数で指定されていません。

プロパティが UtcDateTimeDateTimeOffset.MinValue より前か、 DateTimeOffset.MaxValue より後です。

または

ticksDateTimeOffset.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 しようとすると、 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)

指定した 、、および を使用して、 DateTimeOffset 構造体の新しいインスタンスを初期化しますoffsettimedate

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)

指定した年、月、日、時、分、秒、およびオフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

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 時間を超えています。

- または -

プロパティが UtcDateTimeDateTimeOffset.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

注釈

このコンストラクターは、yearグレゴリオ暦の年、月、日として、、monthdayおよび を解釈します。 別のカレンダーで DateTimeOffset 年、月、日を使用して値をインスタンス化するには、 コンストラクターを DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) 呼び出します。

こちらもご覧ください

適用対象

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)

指定した年、月、日、時、分、秒、ミリ秒、およびオフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

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 を超えています。

- または -

プロパティが UtcDateTimeDateTimeOffset.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

注釈

このコンストラクターは、yearグレゴリオ暦の年、月、日として、、monthdayおよび を解釈します。 別のカレンダーで DateTimeOffset 年、月、日を使用して値をインスタンス化するには、 コンストラクターを DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) 呼び出します。

こちらもご覧ください

適用対象

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan)

指定した暦の指定した年、月、日、時、分、秒、ミリ秒、およびオフセットを使用して、DateTimeOffset 構造体の新しいインスタンスを初期化します。

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 を使用することはできません。

yearcalendar パラメーターの MinSupportedDateTime.Year に満たないか、MaxSupportedDateTime.Year を超えています。

- または -

month が、calendaryear の月数に満たないか、月数を超えています。

- または -

day が 1 未満であるか、month の月の日数を超えています。

- または -

hour が 0 未満であるか、23 を超えています。

- または -

minute が 0 未満であるか、または 59 を超えています。

または

second が 0 未満であるか、または 59 を超えています。

または

millisecond が 0 未満であるか、または 999 を超えています。

- または -

offset が -14 時間より小さいか、14 時間を超えています。

- または -

yearmonth、および day の各パラメーターを日時の値として表すことができません。

- または -

プロパティが UtcDateTimeDateTimeOffset.MinValue より前か、 DateTimeOffset.MaxValue より後です。

次の例では、 クラスと クラスの両方のインスタンスをHebrewCalendarHijriCalendar使用して値を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()

注釈

monthdayhourminutesecond、および millisecond パラメーターはすべてyear、 パラメーターで指定されたカレンダーで表される値をcalendar反映します。 これらの値が、このカレンダーを使用して表現できない日付と時刻を形成する場合は、例外がスローされます。

重要

和暦の時代 (年号) は天皇の代に基づいているため、変更されることが予想されます。 たとえば、JapaneseCalendarJapaneseLunisolarCalendar において、2019 年 5 月 1 日から令和時代が始まることになりました。 このような時代 (年号) の変更は、これらのカレンダーを使用するすべてのアプリケーションに影響します。 詳細と、アプリケーションが影響を受けるかどうかを判断するには、「 .NET での日本語カレンダーでの新しい時代の処理」を参照してください。 Windows システムでアプリケーションをテストして時代 (年号) の変更に対する準備を確認する方法については、「 日本の時代 (年号) に合わせてアプリケーションを準備する」を参照してください。 複数の時代 (年号) を含むカレンダーをサポートする .NET の機能と、複数の時代 (年号) をサポートするカレンダーを操作する場合のベスト プラクティスについては、「 年号の操作」を参照してください。

こちらもご覧ください

適用対象

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan)

指定した monthyearsecondmicroseconddayhourminutemillisecond、および を使用して、 構造体の新しいインスタンスDateTimeOffsetoffset初期化します。

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 を超えています。

注釈

このコンストラクターは、 yearグレゴリオ暦の年、月、日として、および monthday を解釈します。 別のカレンダーで DateTimeOffset 年、月、日を使用して値をインスタンス化するには、 コンストラクターを DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) 呼び出します。

適用対象

DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan)

指定した yearminutesecondmicrosecondmonthdayhourmillisecondおよび を使用して、 構造体のDateTimeOffset新しいインスタンスを初期化します。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);
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 が端数なしの分数を表していません。

yearcalendar でサポートされる範囲にありません。

または

month は 1 未満か、calendar の月数を超えています。

または

day が 1 未満であるか、または monthの日数を超えています。

または

hour が 0 未満であるか、または 23 を超えています。

または

minute が 0 未満であるか、または 59 を超えています。

または

second が 0 未満であるか、または 59 を超えています。

または

millisecond が 0 未満であるか、または 999 を超えています。

- または -

microsecond が 0 未満であるか、または 999 を超えています。

- または -

offset が -14 時間より小さいか、14 時間を超えています。

- または -

yearmonth、および day の各パラメーターを日時の値として表すことができません。

- または -

UtcDateTime プロパティが MinValue よりも前か、MaxValue よりも後です。

注釈

このコンストラクターは、 yearグレゴリオ暦の年、月、日として、 month および day を解釈します。 別のカレンダーで DateTimeOffset 年、月、日を使用して値をインスタンス化するには、 コンストラクターを DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) 呼び出します。

適用対象