Create DateTimeOffset from number of ticks and offset in CSharp
Description
The following code shows how to create DateTimeOffset from number of ticks and offset.
Example
using System;//from w w w. j a v a 2 s .c o m
public class MainClass{
public static void Main(String[] argv){
DateTime localTime = DateTime.Now;
DateTimeOffset nonLocalDateWithOffset = new DateTimeOffset(localTime.Ticks,
new TimeSpan(2, 0, 0));
Console.WriteLine(nonLocalDateWithOffset);
DateTime dateWithoutOffset = new DateTime(2014, 6, 16, 13, 32, 00);
DateTimeOffset timeFromTicks = new DateTimeOffset(dateWithoutOffset.Ticks,
new TimeSpan(-5, 0, 0));
Console.WriteLine(timeFromTicks.ToString());
}
}
The code above generates the following result.