C# TicksPer constants

The TicksPer constants in C# are predefined values in the TimeSpan class that represent the number of ticks for different time units. A tick is the smallest unit of time measurement in .NET, where one tick equals 100 nanoseconds. These constants help convert between ticks and common time measurements.

Available TicksPer Constants

The TimeSpan class provides the following TicksPer constants −

  • TicksPerDay − Number of ticks in one day

  • TicksPerHour − Number of ticks in one hour

  • TicksPerMinute − Number of ticks in one minute

  • TicksPerSecond − Number of ticks in one second

  • TicksPerMillisecond − Number of ticks in one millisecond

Time Unit Hierarchy 1 Day = 864,000,000,000 ticks 1 Hour = 36,000,000,000 ticks 1 Minute = 600,000,000 ticks 1 Second = 10,000,000 ticks 1 Millisecond = 10,000 ticks

Using All TicksPer Constants

Example

using System;

public class Demo {
   public static void Main() {
      Console.WriteLine("TicksPer Constants:");
      Console.WriteLine("TicksPerDay: " + TimeSpan.TicksPerDay);
      Console.WriteLine("TicksPerHour: " + TimeSpan.TicksPerHour);
      Console.WriteLine("TicksPerMinute: " + TimeSpan.TicksPerMinute);
      Console.WriteLine("TicksPerSecond: " + TimeSpan.TicksPerSecond);
      Console.WriteLine("TicksPerMillisecond: " + TimeSpan.TicksPerMillisecond);
   }
}

The output of the above code is −

TicksPer Constants:
TicksPerDay: 864000000000
TicksPerHour: 36000000000
TicksPerMinute: 600000000
TicksPerSecond: 10000000
TicksPerMillisecond: 10000

Practical Application

Example

using System;

public class Demo {
   public static void Main() {
      long totalTicks = DateTime.Now.Ticks;
      
      // Convert ticks to different time units
      long days = totalTicks / TimeSpan.TicksPerDay;
      long hours = (totalTicks % TimeSpan.TicksPerDay) / TimeSpan.TicksPerHour;
      long minutes = (totalTicks % TimeSpan.TicksPerHour) / TimeSpan.TicksPerMinute;
      
      Console.WriteLine("Current DateTime in ticks: " + totalTicks);
      Console.WriteLine("Days since January 1, 0001: " + days);
      Console.WriteLine("Remaining hours: " + hours);
      Console.WriteLine("Remaining minutes: " + minutes);
      
      // Create TimeSpan using ticks
      TimeSpan ts = new TimeSpan(5 * TimeSpan.TicksPerHour + 30 * TimeSpan.TicksPerMinute);
      Console.WriteLine("TimeSpan created: " + ts);
   }
}

The output of the above code is −

Current DateTime in ticks: 638679542400000000
Days since January 1, 0001: 739230
Remaining hours: 4
Remaining minutes: 0
TimeSpan created: 05:30:00

Conclusion

TicksPer constants in C# provide a convenient way to work with time measurements at the tick level. These constants are essential for precise time calculations, converting between different time units, and creating TimeSpan objects with specific durations based on ticks.

Updated on: 2026-03-17T07:04:35+05:30

284 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements