In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to judge a date by JavaScript". In daily operation, I believe many people have doubts about how to judge a date by JavaScript. The editor consulted all kinds of materials and sorted out a simple and easy-to-use method of operation. I hope it will be helpful to answer the doubt of "how to judge a date by JavaScript". Next, please follow the editor to study!
In JavaScript, you can use the isNaN () method and the parse () method of the Date object to determine whether it is a date or not, and the parse () method parses a date-time string; the syntax "if (isNaN (data) & &! isNaN (Date.parse (data))").
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
In JavaScript, you can use the parse () method and isNaN () method of the Date object to determine whether it is a date or not.
Use the isNaN () method to exclude pure numbers, and then use the Date.parse () method to determine whether it is a date or not.
Implementation code:
Var data = "2021-11-03" if (isNaN (data) & &! isNaN (Date.parse (data) {console.log (data+ "is the date format!") ;}
Description:
The isNaN () function is used to check whether its parameters are non-numeric. Returns true if the parameter value is NaN or non-numeric values such as string, object, undefined, etc., otherwise it returns false.
The parse () method parses a date-time string and returns the number of milliseconds from midnight on 1970-1-1 to that date-time.
Syntax: Date.parse (datestring)
Datestring: a required parameter that represents a string of dates and times.
Return value: the specified date and time according to the number of milliseconds between midnight (GMT time) on 1970-1-1.
Description: this method is a static method of the Date object. It is generally called in the form of Date.parse (), rather than through dateobject.parse ().
At this point, the study on "how to judge whether the JavaScript is a date or not" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.