Search code examples
javascriptdatetimeunix-timestampfaker

Timestamp intervals in JavaScript


How can I pick a past date that is a Tuesday or Monday, then get timestamps at 2 week intervals in JavaScript? I am using faker.js. I can only get a date in the past in years, 2 and 1 as shown below.

const releaseStart1 = new Date(faker.date.past(2, new Date(Date.now()))); const releaseEnd1 = new Date(faker.date.past(1, new Date(Date.now())));


Solution

  • Look at using moment as it will let you do something like

    let date = moment().subtract(7, 'days').format();

    Which will return the date. You can use days weeks months seconds minutes hours etc

    https://momentjs.com/docs/