How to check if a string is a valid date in js

I have a string field that is used to get different values. Some of the values โ€‹โ€‹obtained are dates. Now I need to check if the received value is a date or not? The received date may be in different formats again.

I tried Date.parse() , it works if the format is dd-mm-yyyy hh:mm , but I have several dates received as ( 26/05/2015 06:20:57 +00:00 ).

How to compare if a string is a valid date or not?

+6
source share
1 answer

If Date.parse() not enough for you - but that might be enough - see the documentation at:

then you can try:

This is a library for analyzing, checking, processing and displaying dates in JavaScript, which has a much richer API than the standard JavaScript date processing functions.

See also this answer for additional libraries and tutorial links.

+8
source

Source: https://habr.com/ru/post/989132/


All Articles