Do an implicit conversion of a DateTime object to a DateTimeOffset object in CSharp
Description
The following code shows how to do an implicit conversion of a DateTime object to a DateTimeOffset object.
Example
/* w ww .ja v a 2 s.co m*/
using System;
public class MainClass{
public static void Main(String[] argv){
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(2014, 1, 1, 2, 30, 0) +
new TimeSpan(1, 0, 0, 0);
Console.WriteLine(timeWithOffset.ToString());
}
}
The code above generates the following result.