How to convert the format of a javascript date to ISO "International Standard"?

0

I have here a code that performs a javascript operation. It determines the maximum date of birth that can be entered on a form. The rule is that you can only register who is 18 years and over.

var d = new Date();
var year = d.getFullYear();
var month = d.getMonth();
var day = d.getDate();
var dtMax = new Date(year - 18, month, day);

How to pass this date from Wed May 03 2000 00:00:00 GMT-0400 (EDT) to 2000-05-03 - International Standard ISO? The toISOString() method should return the desired value.This value will be used to limit the maximum date of a

asked by anonymous 03.05.2018 / 17:54

1 answer

1

I'm not sure whether to narrow a line in the code is more direct: D

var d = new Date();
d.setFullYear( d.getFullYear() - 18 );
var newdate = (d.toLocaleDateString()).split("/").reverse().join("-");
console.log(newdate);
    
04.05.2018 / 02:47