create a unix timestamp for 2 days time in javascript

To create a Unix timestamp for 2 days time in JavaScript, you can use the Date object along with some arithmetic calculations. Here's an example code snippet:

index.tsx
// Get the current date and time
let now = new Date();

// Add 2 days to the current date
let timestamp = now.setHours(now.getHours() + 48);

// Convert the timestamp to Unix format
timestamp = Math.floor(timestamp / 1000);

console.log(timestamp); // Output: Unix timestamp for 2 days time
291 chars
11 lines

In this example, we first create a new Date object representing the current date and time. We then add 2 days to the current date by using the setHours() method, which takes an argument in hours. Since there are 24 hours in a day, we add 48 hours to get 2 days.

Next, we convert the timestamp to Unix format by dividing it by 1000 and rounding it down using the Math.floor() method. Finally, we log the Unix timestamp to the console.

Note that the Unix timestamp represents the number of seconds elapsed since January 1, 1970, so it is always in UTC timezone.

gistlibby LogSnag