I am getting date in ISO format using moment.js using:
let matchDate= moment().add(1, 'day').toISOString();
It gives me matchDate in the form:
2017-08-01T18:30:00.000Z
I want to set each numeric value after T as 0 and get the result as
2017-08-01T00:00:00.000Z
How can I do this?
You have several possibilities.
Here are some:
let matchDate = moment();
matchDate.set('hour', 0);
matchDate.set('minute', 0);
matchDate.set('second', 0);
matchDate.set('millisecond', 0);
matchDate.set({'hour': 0, 'minute': 0, 'second': 0, 'millisecond': 0});
matchDate.hour(0);
matchDate.minute(0);
matchDate.second(0);
matchDate.millisecond(0);
Here is the documentation about getting and setting: https://momentjs.com/docs/#/get-set/set/
Or, if you don't want to set the time part and doing it in formatting, you can use this:
let matchDate = moment();
var dateString = matchDate.format('YYYY-MM-DD') + 'T00:00:00.000Z';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With