How can I determine whether a given string represents a date?

后端 未结 11 1625
一个人的身影
一个人的身影 2020-12-11 00:31

Is there an isDate function in jQuery?

It should return true if the input is a date, and false otherwise.

11条回答
  •  时光取名叫无心
    2020-12-11 01:17

    There's no built-in date functionality in jQuery core...and it doesn't really do anything directly to help with dates, so there aren't many libraries on top of it (unless they're date pickers, etc). There are several JavaScript date libraries available though, to make working with them just a bit easier.

    I can't answer for sure what's best...it depends how they're entering it and what culture you're dealing with, keep in mind that different cultures are used to seeing their dates in different format, as a quick example, MM/DD/YYYY vs YYYY/MM/DD (or dozens of others).

提交回复
热议问题