internal static DateTime BootTimeToDateTime(TimeSpan timespanAfterBoot)
{
// Use the uptime and the current time to determine the absolute boot time. This implementation is relying on the
// implementation detail that Stopwatch.GetTimestamp() uses a value based on time since boot.
DateTime bootTime = DateTime.UtcNow - TimeSpan.FromSeconds(Stopwatch.GetTimestamp() / (double)Stopwatch.Frequency);
// And use that to determine the absolute time for timespan.
DateTime dt = bootTime + timespanAfterBoot;
// The return value is expected to be in the local time zone.
// It is converted here (rather than starting with DateTime.Now) to avoid DST issues.
return dt.ToLocalTime();
}