C# DateTimeOffset DateTimeOffset(Int64, TimeSpan)
Description
DateTimeOffset DateTimeOffset(Int64, TimeSpan)
initializes
a new instance of the DateTimeOffset structure using the specified number
of ticks and offset.
Syntax
DateTimeOffset.DateTimeOffset(Int64, TimeSpan)
has the following syntax.
public DateTimeOffset(
long ticks,
TimeSpan offset
)
Parameters
DateTimeOffset.DateTimeOffset(Int64, TimeSpan)
has the following parameters.
ticks
- A date and time expressed as the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight on January 1, 0001.offset
- The time's offset from Coordinated Universal Time (UTC).
Example
The following example uses the local time's number of ticks to instantiate a DateTimeOffset value whose offset does not necessarily represent that of the local time:
using System;//from ww w . j a v a2s.com
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.