-4

How can I get a UTC timestamp of a week ago in ISO 8601 format (i.e., YYYY-MM-DDTHH:MM:SSZ) using JavaScript?

I don't want to use any libraries.

Shane Bishop
  • 3,905
  • 4
  • 17
  • 47

1 Answers1

1

Using standard Date functions:

const d = new Date();

d.setDate(d.getDate() - 7);

console.log(d.toISOString());
jarmod
  • 71,565
  • 16
  • 115
  • 122