DateTimeOffset.Implicit(DateTime to DateTimeOffset) Operador
Definição
Define uma conversão implícita de um objeto DateTime como um objeto DateTimeOffset.Defines an implicit conversion of a DateTime object to a DateTimeOffset object.
public:
static operator DateTimeOffset(DateTime dateTime);
public static implicit operator DateTimeOffset (DateTime dateTime);
static member op_Implicit : DateTime -> DateTimeOffset
Public Shared Widening Operator CType (dateTime As DateTime) As DateTimeOffset
Parâmetros
- dateTime
- DateTime
O objeto a ser convertido.The object to convert.
Retornos
O objeto convertido.The converted object.
Exceções
A data e hora em UTC (Tempo Universal Coordenado) que resultam da aplicação do deslocamento são anteriores a MinValue.The Coordinated Universal Time (UTC) date and time that results from applying the offset is earlier than MinValue.
- ou --or- A data e hora UTC que resulta da aplicação do deslocamento é posterior a MaxValue.The UTC date and time that results from applying the offset is later than MaxValue.
Comentários
O Implicit método permite que o compilador converta automaticamente um DateTime objeto em um DateTimeOffset objeto sem um operador de conversão explícito (em C#) ou uma chamada para uma função de conversão (em Visual Basic).The Implicit method enables the compiler to automatically convert a DateTime object to a DateTimeOffset object without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). Ele define uma conversão de ampliação que não envolve a perda de dados e não lança um OverflowException .It defines a widening conversion that does not involve data loss and does not throw an OverflowException. O Implicit método torna um código como o seguinte possível:The Implicit method makes code such as the following possible:
DateTimeOffset timeWithOffset;
timeWithOffset = new DateTime(2008, 7, 3, 18, 45, 0);
Console.WriteLine(timeWithOffset.ToString());
timeWithOffset = DateTime.UtcNow;
Console.WriteLine(timeWithOffset.ToString());
timeWithOffset = DateTime.SpecifyKind(DateTime.Now,
DateTimeKind.Unspecified);
Console.WriteLine(timeWithOffset.ToString());
timeWithOffset = new DateTime(2008, 7, 1, 2, 30, 0) +
new TimeSpan(1, 0, 0, 0);
Console.WriteLine(timeWithOffset.ToString());
timeWithOffset = new DateTime(2008, 1, 1, 2, 30, 0);
Console.WriteLine(timeWithOffset.ToString());
// The example produces the following output if run on 3/20/2007
// at 6:25 PM on a computer in the U.S. Pacific Daylight Time zone:
// 7/3/2008 6:45:00 PM -07:00
// 3/21/2007 1:25:52 AM +00:00
// 3/20/2007 6:25:52 PM -07:00
// 7/2/2008 2:30:00 AM -07:00
// 1/1/2008 2:30:00 AM -08:00
//
// The last example shows automatic adaption to the U.S. Pacific Time
// for winter dates.
Dim timeWithOffset As DateTimeOffset
timeWithOffset = #07/03/2008 6:45PM#
Console.WriteLine(timeWithOffset.ToString())
timeWithOffset = Date.UtcNow
Console.WriteLine(timeWithOffset.ToString())
timeWithOffset = Date.SpecifyKind(Date.Now, DateTimeKind.Unspecified)
Console.WriteLine(timeWithOffset.ToString())
timeWithOffset = #07/01/2008 2:30AM# + New TimeSpan(1, 0, 0, 0)
Console.WriteLine(timeWithOffset.ToString())
timeWithOffset = #01/01/2008 2:30AM#
Console.WriteLine(timeWithOffset.ToString())
' The example produces the following output if run on 3/20/2007
' at 6:25 PM on a computer in the U.S. Pacific Daylight Time zone:
' 7/3/2008 6:45:00 PM -07:00
' 3/21/2007 1:25:52 AM +00:00
' 3/20/2007 6:25:52 PM -07:00
' 7/2/2008 2:30:00 AM -07:00
' 1/1/2008 2:30:00 AM -08:00
'
' The last example shows automatic adaption to the U.S. Pacific Time
' for winter dates.
Esse método é equivalente ao DateTimeOffset Construtor.This method is equivalent to the DateTimeOffset constructor. O deslocamento do objeto resultante DateTimeOffset depende do valor da DateTime.Kind Propriedade do dateTime parâmetro:The offset of the resulting DateTimeOffset object depends on the value of the DateTime.Kind property of the dateTime parameter:
Se o valor da DateTime.Kind propriedade for DateTimeKind.Utc , a data e a hora do DateTimeOffset objeto serão definidas como igual a
dateTime, e sua Offset propriedade será definida igual a 0.If the value of the DateTime.Kind property is DateTimeKind.Utc, the date and time of the DateTimeOffset object is set equal todateTime, and its Offset property is set equal to 0.Se o valor da DateTime.Kind propriedade for DateTimeKind.Local ou DateTimeKind.Unspecified , a data e hora do DateTimeOffset objeto será definida como igual a
dateTimee sua Offset propriedade será definida igual ao deslocamento do fuso horário atual do sistema local.If the value of the DateTime.Kind property is DateTimeKind.Local or DateTimeKind.Unspecified, the date and time of the DateTimeOffset object is set equal todateTime, and its Offset property is set equal to the offset of the local system's current time zone.
O método equivalente para esse operador é DateTimeOffset.DateTimeOffset(DateTime)The equivalent method for this operator is DateTimeOffset.DateTimeOffset(DateTime)