javascriptdatetimefiletime

Convert Javascript Date object to Filetime


Can't believe I'm unable to find the very simple case of converting a Javascript date object to Filetime.
The other way around popped up a lot while searching.

I have provided the solution below for anyone else who is looking for it.


Solution

  • To convert now to Filetime:

    function filetimeFromDate(date) {  
        return date.getTime() * 1e4 + 116444736e9;
    }
    const now = new Date();
    const filetimeNow = filetimeFromDate(now);
    console.log(filetimeNow);