0

I receive a date as a string of 18 numbers such (Example: "636664860000000000") from an API that uses .NET.

Based on my research, it is a windows SYSTEMTIME format value that needs to be converted to FILETIME then UTC. I am unable to find a way to do this other than through the back end itself.

Is there a way to convert this number to a UTC time stamp with JavaScript?

Randy Lam
  • 51
  • 3
  • possible duplicate of https://stackoverflow.com/questions/6161776/convert-windows-filetime-to-second-in-unix-linux. – ManavM Jun 27 '18 at 02:48
  • I believe this is FILETIME to Unix and its not quite what I'm looking for. If you run the .toString() method in C#, it will return the correct value of July, 6 2018 3:00PM. If you can find the formula for SYSTEMTIME to FILETIME, then that solution might work. – Randy Lam Jun 27 '18 at 05:58

1 Answers1

0

Give this a try: https://plnkr.co/edit/GXTO1gigMAbumRU643KB?p=preview

function convert(){
  var winTicks = 10000000;
  var uEpoch = 11644473600;
  var time = document.getElementById('filetime').value;

  var unixTime = time/winTicks - uEpoch;
  console.log(unixTime);
  var utc = new Date(unixTime * 1000).toUTCString();
  var label = document.getElementById('utctime');
  label.innerHTML = utc;
}

And compare with this tool: https://www.epochconverter.com/ldap

scotty3
  • 153
  • 8
  • I believe this is FILETIME to Unix and its not quite what I'm looking for. If you run the .toString() method in C#, it will return the correct value of July, 6 2018 3:00PM – Randy Lam Jun 27 '18 at 05:56
  • The formula to convert a FileTime aka LDAP timestamp to UTC is to divide the FileTime by 10,000,000 (to convert from nanoseconds) minus 11644473600 (the difference between a Windows and Unix Epoch). Using the JavaScript .toUTCString() produces the UTC date, you'll need to convert it for timezones. – scotty3 Jun 27 '18 at 19:31