2020年12月30日星期三

How to ensure the date string is in ISO 8061 format in javascript

I have to understand whether the given string is in YYYY-MM-DD format.

I was tetsting using the following code snippet:

const isValidDate = (new Date(timestamp)).getTime() > 0;  

However, in this case, "2015-06-22T13:17:21+0000" will be also valid.

I want to ensure only the day part is present in YYYY-MM-DD.

What would be a neat concise way to determine this in javascript.

https://stackoverflow.com/questions/65516502/how-to-ensure-the-date-string-is-in-iso-8061-format-in-javascript December 31, 2020 at 12:07PM

没有评论:

发表评论