Search code examples
javascriptluxon

How to get the timestamp from a Luxon DateTime object?


How can I get the Timestamp from a luxon dateTime object?

For example?

const { DateTime } = require("luxon");

date = DateTime.now().setZone('utc');
date.endOf('day);

console.log(date.???) // should give something like 1629399474922

This should be the equivalent to javascript's Date.getTime() function.


Solution

  • The Luxon docs are surprisingly silent on this, but after some digging I finally found it:

    date.toMillis(); 
    // or 
    date.valueOf();