For Developers
How to get the current timestamp, convert it to a date, and convert a date back to a timestamp in F#, using .NET's DateTimeOffset under the hood.
open System
let ts = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
let ts = 1750000000L
let dt = DateTimeOffset.FromUnixTimeSeconds(ts)
printfn "%s" (dt.ToString("u"))
let dt = DateTimeOffset(2025, 6, 15, 12, 0, 0, TimeSpan.Zero)
let ts = dt.ToUnixTimeSeconds()
F# runs on .NET and inherits its date/time types wholesale, including the same trap C# developers hit: plain DateTime carries a Kind property (Local, Utc, or Unspecified) that's easy to leave as the default "Unspecified," which silently skips timezone conversion logic that would otherwise catch a mismatch. DateTimeOffset avoids this ambiguity entirely by always carrying an explicit offset, which is why the snippets above use it instead of plain DateTime — idiomatic F# code generally prefers it for exactly this reason, on top of the language's broader preference for immutable, unambiguous values.
Paste it into the Timestamp ⇄ Date Converter to check it instantly, in any timezone, without writing any code. Working across several languages on the same project? The full Epoch Time in Programming Languages guide has all of them side by side for quick comparison.
Related
Every language's snippets side by side, for quick comparison.
Convert any timestamp instantly, no code required.
The same underlying .NET DateTimeOffset API, in C# syntax.