DateTimeOffset Costruttori

Definizione

Inizializza una nuova istanza della struttura DateTimeOffset.

Overload

DateTimeOffset(DateTime)

Inizializza una nuova istanza della struttura DateTimeOffset usando il valore DateTime specificato.

DateTimeOffset(DateTime, TimeSpan)

Inizializza una nuova istanza della struttura DateTimeOffset usando il valore e l'offset della struttura DateTime specificati.

DateTimeOffset(Int64, TimeSpan)

Inizializza una nuova istanza della struttura DateTimeOffset usando il numero di tick e l'offset specificati.

DateTimeOffset(DateOnly, TimeOnly, TimeSpan)

Inizializza una nuova istanza della DateTimeOffset struttura utilizzando l'oggetto , timee offsetspecificatidate.

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

Inizializza una nuova istanza della struttura DateTimeOffset usando l'anno, il mese, il giorno, l'ora, il minuto, il secondo e l'offset specificati.

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

Inizializza una nuova istanza della struttura DateTimeOffset usando l'anno, il mese, il giorno, l'ora, il minuto, il secondo, il millisecondo e l'offset specificati.

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

Inizializza una nuova istanza della struttura DateTimeOffset usando l'anno, il mese, il giorno, l'ora, il minuto, il secondo, il millisecondo e l'offset specificati di un determinato calendario.

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

Inizializza una nuova istanza della DateTimeOffset struttura utilizzando l'oggetto specificatoyear, , month, hourday, minutesecond, millisecond, microsecond e offset.

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

Inizializza una nuova istanza della DateTimeOffset struttura utilizzando l'oggetto specificatoyear, , month, hourday, minutesecond, millisecond, microsecond e offset.

DateTimeOffset(DateTime)

Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs

Inizializza una nuova istanza della struttura DateTimeOffset usando il valore DateTime specificato.

public:
 DateTimeOffset(DateTime dateTime);
public DateTimeOffset (DateTime dateTime);
new DateTimeOffset : DateTime -> DateTimeOffset
Public Sub New (dateTime As DateTime)

Parametri

dateTime
DateTime

Data e ora.

Eccezioni

La data e l'ora UTC (Coordinated Universal Time) risultanti dall'applicazione dell'offset sono precedenti a DateTimeOffset.MinValue.

-oppure-

La data e l'ora UTC risultante dall'applicazione dell'offset sono successive a DateTimeOffset.MaxValue.

Esempio

Nell'esempio seguente viene illustrato come il valore della DateTime.Kind proprietà del dateTime parametro influisce sul valore di data e ora restituito da questo costruttore.

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

Commenti

Il comportamento di questo costruttore dipende dal valore della DateTime.Kind proprietà del dateTime parametro :

Vedi anche

Si applica a

DateTimeOffset(DateTime, TimeSpan)

Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs

Inizializza una nuova istanza della struttura DateTimeOffset usando il valore e l'offset della struttura DateTime specificati.

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)

Parametri

dateTime
DateTime

Data e ora.

offset
TimeSpan

Offset dell'ora rispetto all'ora UTC (Coordinated Universal Time).

Eccezioni

dateTime.Kind è uguale a Utc e offset non è uguale a zero.

-oppure-

dateTime.Kind è uguale a Local e offset non è uguale all'offset del fuso orario locale del sistema.

-oppure-

offset non è specificato in minuti interi.

offset è minore di -14 ore o maggiore di 14 ore.

-oppure-

UtcDateTime è minore di DateTimeOffset.MinValue o maggiore di DateTimeOffset.MaxValue.

Esempio

Nell'esempio seguente viene illustrato come inizializzare un DateTimeOffset oggetto con una data e un'ora e l'offset del fuso orario locale quando tale fuso orario non è noto in anticipo.

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

Commenti

Il comportamento di questo costruttore dipende in parte dal valore della Kind proprietà del dateTime parametro :

Vedi anche

Si applica a

DateTimeOffset(Int64, TimeSpan)

Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs

Inizializza una nuova istanza della struttura DateTimeOffset usando il numero di tick e l'offset specificati.

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)

Parametri

ticks
Int64

Data e ora espresse come numero di intervalli da 100 nanosecondi trascorsi dalle ore 12.00.00, mezzanotte del 1 gennaio 0001.

offset
TimeSpan

Offset dell'ora rispetto all'ora UTC (Coordinated Universal Time).

Eccezioni

offset non è specificato in minuti interi.

La UtcDateTime proprietà è precedente a DateTimeOffset.MinValue o successiva a DateTimeOffset.MaxValue.

-oppure-

ticks è minore di DateTimeOffset.MinValue.Ticks o maggiore di DateTimeOffset.MaxValue.Ticks.

-oppure-

Offset è minore di -14 ore o maggiore di 14 ore.

Esempio

Nell'esempio seguente viene inizializzato un DateTimeOffset oggetto utilizzando il numero di tick in una data arbitraria (in questo caso, il 16 luglio 2007, alle 13:32) con un offset pari a -5.

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

Commenti

In genere, il tentativo di chiamare il costruttore per creare un'istanza DateTimeOffset di un valore con un'ora DateTimeOffset locale e un offset diverso da quello del fuso orario locale genera un'eccezione ArgumentException. È possibile usare questo overload del DateTimeOffset costruttore per ovviare a questa limitazione. Nell'esempio seguente viene utilizzato il numero di tick dell'ora locale per creare un'istanza di un DateTimeOffset valore il cui offset non rappresenta necessariamente quello dell'ora locale:

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

Vedi anche

Si applica a

DateTimeOffset(DateOnly, TimeOnly, TimeSpan)

Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs

Inizializza una nuova istanza della DateTimeOffset struttura utilizzando l'oggetto , timee offsetspecificatidate.

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)

Parametri

date
DateOnly

Parte della data.

time
TimeOnly

Parte dell'ora.

offset
TimeSpan

Offset dell'ora rispetto all'ora UTC (Coordinated Universal Time).

Si applica a

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

Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs

Inizializza una nuova istanza della struttura DateTimeOffset usando l'anno, il mese, il giorno, l'ora, il minuto, il secondo e l'offset specificati.

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)

Parametri

year
Int32

Anno (da 1 a 9999).

month
Int32

Mese (da 1 a 12).

day
Int32

Giorno (da 1 al numero di giorni in month).

hour
Int32

Ore (da 0 a 23).

minute
Int32

Minuti (da 0 a 59).

second
Int32

Secondi (da 0 a 59).

offset
TimeSpan

Offset dell'ora rispetto all'ora UTC (Coordinated Universal Time).

Eccezioni

offset non rappresenta minuti interi.

year è minore di 1 o maggiore di 9999.

-oppure-

month è minore di 1 o maggiore di 12.

-oppure-

day è minore di 1 o maggiore del numero di giorni in month.

-oppure-

hour è minore di zero o maggiore di 23.

-oppure-

minute è minore di 0 o maggiore di 59.

-oppure-

second è minore di 0 o maggiore di 59.

-oppure-

offset è minore di -14 ore o maggiore di 14 ore.

-oppure-

La UtcDateTime proprietà è precedente a DateTimeOffset.MinValue o successiva a DateTimeOffset.MaxValue.

Esempio

Nell'esempio seguente viene creata un'istanza di un DateTimeOffset oggetto usando l'overload del DateTimeOffset.DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan) costruttore.

   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

Commenti

Questo costruttore interpreta year, monthe day come anno, mese e giorno nel calendario gregoriano. Per creare un'istanza di un DateTimeOffset valore usando anno, mese e giorno in un altro calendario, chiamare il DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) costruttore.

Vedi anche

Si applica a

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

Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs

Inizializza una nuova istanza della struttura DateTimeOffset usando l'anno, il mese, il giorno, l'ora, il minuto, il secondo, il millisecondo e l'offset specificati.

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)

Parametri

year
Int32

Anno (da 1 a 9999).

month
Int32

Mese (da 1 a 12).

day
Int32

Giorno (da 1 al numero di giorni in month).

hour
Int32

Ore (da 0 a 23).

minute
Int32

Minuti (da 0 a 59).

second
Int32

Secondi (da 0 a 59).

millisecond
Int32

Millisecondi (da 0 a 999).

offset
TimeSpan

Offset dell'ora rispetto all'ora UTC (Coordinated Universal Time).

Eccezioni

offset non rappresenta minuti interi.

year è minore di 1 o maggiore di 9999.

-oppure-

month è minore di 1 o maggiore di 12.

-oppure-

day è minore di 1 o maggiore del numero di giorni in month.

-oppure-

hour è minore di zero o maggiore di 23.

-oppure-

minute è minore di 0 o maggiore di 59.

-oppure-

second è minore di 0 o maggiore di 59.

-oppure-

millisecond è minore di 0 o maggiore di 999.

-oppure-

offset è minore di -14 o maggiore di 14.

-oppure-

La UtcDateTime proprietà è precedente a DateTimeOffset.MinValue o successiva a DateTimeOffset.MaxValue.

Esempio

Nell'esempio seguente viene creata un'istanza di un DateTimeOffset oggetto usando l'overload del DateTimeOffset.DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, TimeSpan) costruttore.

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

Commenti

Questo costruttore interpreta year, monthe day come anno, mese e giorno nel calendario gregoriano. Per creare un'istanza di un DateTimeOffset valore usando anno, mese e giorno in un altro calendario, chiamare il DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) costruttore.

Vedi anche

Si applica a

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

Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs

Inizializza una nuova istanza della struttura DateTimeOffset usando l'anno, il mese, il giorno, l'ora, il minuto, il secondo, il millisecondo e l'offset specificati di un determinato calendario.

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)

Parametri

year
Int32

Anno.

month
Int32

Mese (da 1 a 12).

day
Int32

Giorno (da 1 al numero di giorni in month).

hour
Int32

Ore (da 0 a 23).

minute
Int32

Minuti (da 0 a 59).

second
Int32

Secondi (da 0 a 59).

millisecond
Int32

Millisecondi (da 0 a 999).

calendar
Calendar

Calendario usato per interpretare year, month e day.

offset
TimeSpan

Offset dell'ora rispetto all'ora UTC (Coordinated Universal Time).

Eccezioni

offset non rappresenta minuti interi.

Il parametro calendar non può essere null.

year è minore dell'oggetto MinSupportedDateTime.Year del parametro calendar o maggiore di MaxSupportedDateTime.Year.

-oppure-

month è minore o maggiore del numero di mesi in year nell'oggetto calendar.

-oppure-

day è minore di 1 o maggiore del numero di giorni in month.

-oppure-

hour è minore di zero o maggiore di 23.

-oppure-

minute è minore di 0 o maggiore di 59.

-oppure-

second è minore di 0 o maggiore di 59.

-oppure-

millisecond è minore di 0 o maggiore di 999.

-oppure-

offset è minore di -14 ore o maggiore di 14 ore.

-oppure-

I parametri year, month e day non possono essere rappresentati come valore di data e ora.

-oppure-

La UtcDateTime proprietà è precedente a DateTimeOffset.MinValue o successiva a DateTimeOffset.MaxValue.

Esempio

Nell'esempio seguente vengono usate istanze della HebrewCalendar classe e della HijriCalendar classe per creare un'istanza di un DateTimeOffset valore. Tale data viene quindi visualizzata nella console utilizzando i rispettivi calendari e il calendario gregoriano.

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()

Commenti

I yearparametri , daymonth, hour, minute, second, e millisecond riflettono tutti i valori espressi nel calendario specificato dal calendar parametro . Viene generata un'eccezione se questi valori formano una data e un'ora che non possono essere espresse utilizzando questo calendario.

Importante

Le ere nel calendario giapponese sono basate sul regno dell'imperatore e pertanto è previsto che cambino. Ad esempio, il 1° maggio 2019 contraddistingue l'inizio dell'era Reiwa in JapaneseCalendar e JapaneseLunisolarCalendar. Questo cambio di era interessa tutte le applicazioni che usano questi calendari. Per altre informazioni e per determinare se le applicazioni sono interessate, vedere Gestione di una nuova era nel calendario giapponese in .NET. Per informazioni sul test delle applicazioni nei sistemi Windows per garantire la conformità per il cambiamento dell'era, vedere Preparare l'applicazione per la modifica dell'era giapponese. Per le funzionalità di .NET che supportano calendari con più era e per le procedure consigliate quando si usano calendari che supportano più ere, vedere Uso delle era.

Vedi anche

Si applica a

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

Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs

Inizializza una nuova istanza della DateTimeOffset struttura utilizzando l'oggetto specificatoyear, , month, hourday, minutesecond, millisecond, microsecond e offset.

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)

Parametri

year
Int32

Anno (da 1 a 9999).

month
Int32

Mese (da 1 a 12).

day
Int32

Giorno (da 1 al numero di giorni in month).

hour
Int32

Ore (da 0 a 23).

minute
Int32

Minuti (da 0 a 59).

second
Int32

Secondi (da 0 a 59).

millisecond
Int32

Millisecondi (da 0 a 999).

microsecond
Int32

Microsecondi (da 0 a 999).

offset
TimeSpan

Offset dell'ora rispetto all'ora UTC (Coordinated Universal Time).

Eccezioni

offset non rappresenta minuti interi.

year è minore di 1 o maggiore di 9999.

-oppure-

month è minore di 1 o maggiore di 12.

-oppure-

day è minore di 1 o maggiore del numero di giorni in month.

-oppure-

hour è minore di 0 o maggiore di 23.

-oppure-

minute è minore di 0 o maggiore di 59.

-oppure-

second è minore di 0 o maggiore di 59.

-oppure-

millisecond è minore di 0 o maggiore di 999.

-oppure-

microsecond è minore di 0 o maggiore di 999.

Commenti

Questo costruttore interpreta yeare monthday come anno, mese e giorno nel calendario gregoriano. Per creare un'istanza di un DateTimeOffset valore usando anno, mese e giorno in un altro calendario, chiamare il DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) costruttore.

Si applica a

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

Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs
Source:
DateTimeOffset.cs

Inizializza una nuova istanza della DateTimeOffset struttura utilizzando l'oggetto specificatoyear, , month, hourday, minutesecond, millisecond, microsecond e 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)

Parametri

year
Int32

Anno (da 1 a 9999).

month
Int32

Mese (da 1 a 12).

day
Int32

Giorno (da 1 al numero di giorni in month).

hour
Int32

Ore (da 0 a 23).

minute
Int32

Minuti (da 0 a 59).

second
Int32

Secondi (da 0 a 59).

millisecond
Int32

Millisecondi (da 0 a 999).

microsecond
Int32

Microsecondi (da 0 a 999).

calendar
Calendar

Calendario usato per interpretare year, month e day.

offset
TimeSpan

Offset dell'ora rispetto all'ora UTC (Coordinated Universal Time).

Eccezioni

offset non rappresenta minuti interi.

year non è compreso nell'intervallo supportato da calendar.

-oppure-

month è minore di 1 o maggiore del numero di mesi in calendar.

-oppure-

day è minore di 1 o maggiore del numero di giorni in month.

-oppure-

hour è minore di 0 o maggiore di 23.

-oppure-

minute è minore di 0 o maggiore di 59.

-oppure-

second è minore di 0 o maggiore di 59.

-oppure-

millisecond è minore di 0 o maggiore di 999.

-oppure-

microsecond è minore di 0 o maggiore di 999.

-oppure-

offset è minore di -14 ore o maggiore di 14 ore.

-oppure-

I parametri year, month e day non possono essere rappresentati come valore di data e ora.

-oppure-

La proprietà UtcDateTime è precedente a MinValue o successiva a MaxValue.

Commenti

Questo costruttore interpreta yeare monthday come anno, mese e giorno nel calendario gregoriano. Per creare un'istanza di un DateTimeOffset valore usando anno, mese e giorno in un altro calendario, chiamare il DateTimeOffset(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, TimeSpan) costruttore.

Si applica a