tset tset - 2 months ago 8
Node.js Question

Node.js date format conversion without using modules

Date format conversion without using modules

The following code converts the date into different format: "2016-09-16T04:48:29.250Z"

var date = new Date().toISOString();
console.log(date);


How do I subtract 14 days and then convert the date into the same format?

var date = new Date();
date.setDate(date.getDate()-14);
console.log(date);

Answer

You're very close. Just do:

var date = new Date();
date.setDate(date.getDate() - 14);
console.log(date.toISOString());
Comments