'checking the ISO data format is not working

I'm trying to check if the 'date-time' string is ISO formatted and I get the following output:

isIsoDate the date string is not ISO format! :  2022-04-21T09:40:01.000Z
isIsoDate converted-back date :  2022-04-21T09:40:01.000Z
isIsoDate time stamp number :  1650534001000
isIsoDate string builded back :  Thu Apr 21 2022 11:40:01 GMT+0200 (Ora legale dell’Europa centrale) 

this is my code:

export function isIsoDate(dateString) {
    
        var dateParsedNum = Date.parse(dateString);
        var dateBackToString = new Date(dateParsedNum);
        var stringBuilded = "";
    
    
        stringBuilded = dateBackToString.toString()
    
    
        if ((dateBackToString.toString()) == dateString) {
            return true;
            
        } else {
           console.debug("isIsoDate() the date string is not ISO format! : ", dateString);
           console.debug("isIsoDate() converted-back date : ", dateBackToString);
           console.debug("isIsoDate() time stamp number : ", dateParsedNum);
           console.debug("isIsoDate() string builded back : ", stringBuilded);
           // throw new BadRequestException('Validation failed');
        }
    
        return(false)
    }


Solution 1:[1]

I'm not sure if it can be done with JavaScript's Date utilities. As Salman said in the comments, you can have .toISOString() instead, but this method converts everything into UTC, whereas the ISO specification is more flexible than that.

I recommend this StackOverFlow answer that uses RegEx to validate ISO strings.

Solution 2:[2]

did you check the setting? there is several solutions in the site

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 J Eti
Solution 2 iberiss