I am capturing some events in a C# program that come back with the timestamp as a system tickcount (milliseconds since start time).
Knowing, based on other questions I’ve seen, that I can get the same number from System.Environment.TickCount property (or something else), how can I infer the DateTime object that corresponds to the TickCount I received?
You can’t, without more information (and even then it can be ambiguous).
Environment.TickCountreturns:… so unless you can find out the time the computer was started from somewhere, you’re out of luck. There may well be registry entries or system calls you can make to find out the last boot time, but I don’t know them off the top of my head. Of course, you can get an approximate value by taking
Environment.TickCountyourself andDateTime.UtcNowas soon after (or before) that as possible, and finding the difference between the two:However, even with that, the value will cycle round every 24.9 days, so if the computer has been on for longer than that, the count is ambiguous.
I’d suggest avoiding using
Environment.TickCountif possible, basically – is this under your control at all?