0

I'm using the following code to convert windows time to unix timestamp,

def convert_windows_time(windows_time):
    return datetime.datetime(1601, 1, 1) + datetime.timedelta(microseconds=windows_time / 10)

How can I do the same in nodejs? This does not work, it results in a different date:

let a = parseInt(129436810067618693)
let b = (new Date('1601-01-01').getMilliseconds()) + a / 10
console.log(new Date(b / 10000))

Any ideas what's wrong?

daisy
  • 22,498
  • 29
  • 129
  • 265
  • What is 'windows time'? Where does that come from? Ah, you mean the [Windows epoch](https://stackoverflow.com/questions/10849717/what-is-the-significance-of-january-1-1601). – jarmod Apr 17 '23 at 10:47
  • @jarmod I'm making it symbol, how can I convert the python code to nodejs so that I can run it in the web ui instead ... – daisy Apr 17 '23 at 16:24

1 Answers1

2

Try the following:

const winepoch = new Date('1601-01-01T00:00:00.000Z').getTime();
const unxepoch = new Date('1970-01-01T00:00:00.000Z').getTime();
const difference = unxepoch - winepoch;

const a = 129436810067618693; // measured in 100 ns
console.log(new Date((a / 10000) - difference));
jarmod
  • 71,565
  • 16
  • 115
  • 122