Getting a Unix Timestamp for a future date and time in JavaScript


How can I get a future unix timestamp in Javacript? ie, pass "2023-03-08 13:05:00" and get a unix timestamp corresponding to that time.

All the examples I see use the getTime() function which is the current time like this:
Javascript: future time as UNIX timestamp

I found a solution in Php which I think serves the purpose I am looking for:
Getting a future unix timestamp using a specific date and time?

Is there a similar function in Javascript?

>Solution :

// Create a Date object for the future time

var futureTime = new Date("2023-03-08 13:05:00");

// Get the Unix timestamp (in milliseconds) for the future time

var futureTimestamp = futureTime.getTime();

// Convert milliseconds to seconds

var futureUnixTimestamp = Math.floor(futureTimestamp / 1000);

console.log(futureUnixTimestamp); // Output: 1678385100

Leave a Reply Cancel reply