C# DateTimeOffset DateTimeOffset(DateTime)
Description
DateTimeOffset DateTimeOffset(DateTime)
initializes
a new instance of the DateTimeOffset structure using the specified DateTime
value.
Syntax
DateTimeOffset.DateTimeOffset(DateTime)
has the following syntax.
public DateTimeOffset(
DateTime dateTime
)
Parameters
DateTimeOffset.DateTimeOffset(DateTime)
has the following parameters.
dateTime
- A date and time.
Example
The following example illustrates how the value of the DateTime.Kind property of the dateTime parameter affects the date and time value that is returned by this constructor.
using System;/*from ww w .j av a 2 s . com*/
public class MainClass{
public static void Main(String[] argv){
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 above generates the following result.