Skip to content

fromDotNetTicks

fromDotNetTicks(value: bigint): string

Convert .NET DateTime.Ticks back to an ISO 8601 instant string.

  • value counts 100-nanosecond intervals since 0001-01-01T00:00:00 in the proleptic Gregorian calendar.
  • Only UTC ticks name an instant. .NET counts Ticks in the zone of the DateTime’s Kind: a Local or Unspecified value counts local wall-clock time, and this function reads every value as UTC. Pass DateTime.UtcNow.Ticks or ToUniversalTime().Ticks; DateTime.Now.Ticks on a UTC−5 host decodes five hours early.
  • Accepts DateTime.MinValue (0n) to DateTime.MaxValue (3155378975999999999n, 9999-12-31T23:59:59.9999999). A tick count outside that is not a DateTime, and a negative value in particular is rejected rather than read as a pre-year-1 instant.
  • Pass Ticks, not the raw backing field: .NET packs DateTimeKind into its top two bits, and a Kind-tagged value would decode as an instant thousands of years out.
  • Exact in this direction — 100 ns is coarser than the nanoseconds an ISO string carries, so nothing is rounded. The loss, if any, happened in toDotNetTicks.
  • Returns "" on invalid input.
ParameterTypeDescription
valuebigint100-nanosecond intervals since 0001-01-01 (bigint, 0n to 3155378975999999999n)

ISO 8601 instant string (UTC), or "" on invalid input

import { fromDotNetTicks } from "@northguild/gmt/precision/convert";
fromDotNetTicks(0n) // "0001-01-01T00:00:00Z" — DateTime.MinValue
output 

precision/convert/fromDotNetTicks.ts