C# DateTimeOffset Ticks

Description

DateTimeOffset Ticks gets the number of ticks that represents the date and time of the current DateTimeOffset object in clock time.

Syntax

DateTimeOffset.Ticks has the following syntax.


public long Ticks { get; }

Example

The following example initializes a DateTimeOffset object by approximating the number of ticks.


using System;/*from www  . java 2 s.  co  m*/

public class MainClass{
  public static void Main(String[] argv){  
    const long NSPerSecond = 10000000;
    long ticks; 
    ticks = 7 * NSPerSecond;                        // Ticks in a 7 seconds 
    ticks += 181 * 60 * 60 * 24 * NSPerSecond;      // Ticks in 6 months 
    ticks += 2014 * 60 * 60 * 24 * 365L * NSPerSecond;   // Ticks in 2014 years 
    ticks += 486 * 60 * 60 * 24 * NSPerSecond;      // Adjustment for leap years      
    DateTimeOffset dto = new DateTimeOffset( 
                             ticks, 
                             DateTimeOffset.Now.Offset);
    Console.WriteLine("There are {0:n0} ticks in {1}.", 
                      dto.Ticks, 
                      dto.ToString());

  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version