I have a program that I am converting from C# to Java and have run into a strange issue:
The C# application outputs a 'windows timestamp' via the following code:
private static readonly DateTime epochDateTime = new DateTime(1970, 1, 1); double totalSeconds = seconds + nanosecs / 1000000000.0; wintimestamp = epochDateTime.AddSeconds(totalSeconds).ToFileTimeUtc(); I'm having trouble trying to duplicate the functionality of "ToFileTimeUtc" in Java. I need to keep it since the existing applications that use the data generated from this application are expecting the same data format.
I have tried some this in java and got it to match up. But I would like a deeper explanation as to what I'm doing.
int second = 1589913034; int nanosec = 24; double totalSeconds = second + nanosec / 1_000_000_000.0; System.out.println(totalSeconds); long wintimestamp = (long) (116444736000000000L + totalSeconds * 10_000_000); System.out.println(wintimestamp); I'm pretty sure this value: 116444736000000000L is the epoch equivalence of the 1601 Win32 epoch to the regular java epoch. I got this from doing:
epochDateTime.AddSeconds(totalSeconds).ToFileTimeUtc(); Then I finally started playing around with the multiplier until I got close to the value from the C# call finally landing on 10 million that got me the exact same number. Not sure why though.