{"id":5647,"date":"2023-01-06T11:06:34","date_gmt":"2023-01-06T03:06:34","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5647"},"modified":"2023-01-06T11:06:34","modified_gmt":"2023-01-06T03:06:34","slug":"1-%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8react-js%e4%be%86%e6%aa%a2%e6%9f%a5%e6%97%a5%e6%9c%9f%e6%98%af%e5%90%a6%e6%9c%89%e6%95%88","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/react-js\/1-%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8react-js%e4%be%86%e6%aa%a2%e6%9f%a5%e6%97%a5%e6%9c%9f%e6%98%af%e5%90%a6%e6%9c%89%e6%95%88\/","title":{"rendered":"1.\u5982\u4f55\u4f7f\u7528React.JS\u4f86\u6aa2\u67e5\u65e5\u671f\u662f\u5426\u6709\u6548"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"React.JS, isValidDate\"><\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 React.JS \u6aa2\u67e5\u65e5\u671f\u662f\u5426\u6709\u6548<\/h1>\n<p>\u5728\u958b\u767c\u7db2\u9801\u6642\uff0c\u6aa2\u67e5\u65e5\u671f\u662f\u5426\u6709\u6548\u662f\u4e00\u500b\u5e38\u898b\u7684\u4efb\u52d9\u3002\u6709\u6642\u5019\uff0c\u6211\u5011\u9700\u8981\u6aa2\u67e5\u7528\u6236\u8f38\u5165\u7684\u65e5\u671f\u662f\u5426\u6709\u6548\uff0c\u4ee5\u78ba\u4fdd\u6211\u5011\u7684\u61c9\u7528\u7a0b\u5f0f\u6b63\u5e38\u904b\u884c\u3002\u5728 React.JS \u4e2d\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 JavaScript \u4f86\u6aa2\u67e5\u65e5\u671f\u662f\u5426\u6709\u6548\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u5728 React.JS \u4e2d\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 JavaScript \u4f86\u6aa2\u67e5\u65e5\u671f\u662f\u5426\u6709\u6548\u3002\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 <code>Date<\/code> \u985e\u5225\u4f86\u5275\u5efa\u4e00\u500b\u65e5\u671f\u5c0d\u8c61\uff0c\u4e26\u4f7f\u7528 <code>getFullYear()<\/code> \u65b9\u6cd5\u4f86\u7372\u53d6\u5e74\u4efd\uff0c<code>getMonth()<\/code> \u65b9\u6cd5\u4f86\u7372\u53d6\u6708\u4efd\uff0c<code>getDate()<\/code> \u65b9\u6cd5\u4f86\u7372\u53d6\u65e5\u671f\uff0c\u4ee5\u53ca <code>getDay()<\/code> \u65b9\u6cd5\u4f86\u7372\u53d6\u661f\u671f\u3002<\/p>\n<pre class=\"brush: javascript\">\n\/\/ \u5275\u5efa\u4e00\u500b\u65e5\u671f\u5c0d\u8c61\nlet date = new Date();\n\n\/\/ \u7372\u53d6\u5e74\u4efd\nlet year = date.getFullYear();\n\n\/\/ \u7372\u53d6\u6708\u4efd\nlet month = date.getMonth();\n\n\/\/ \u7372\u53d6\u65e5\u671f\nlet day = date.getDate();\n\n\/\/ \u7372\u53d6\u661f\u671f\nlet dayOfWeek = date.getDay();\n<\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 <code>isValidDate()<\/code> \u65b9\u6cd5\u4f86\u6aa2\u67e5\u65e5\u671f\u662f\u5426\u6709\u6548\u3002\u8a72\u65b9\u6cd5\u63a5\u53d7\u4e09\u500b\u53c3\u6578\uff1a\u5e74\u4efd\uff0c\u6708\u4efd\u548c\u65e5\u671f\u3002\u5982\u679c\u65e5\u671f\u6709\u6548\uff0c\u5247\u8fd4\u56de <code>true<\/code>\uff0c\u5426\u5247\u8fd4\u56de <code>false<\/code>\u3002<\/p>\n<pre class=\"brush: javascript\">\n\/\/ \u6aa2\u67e5\u65e5\u671f\u662f\u5426\u6709\u6548\nfunction isValidDate(year, month, day) {\n  let date = new Date(year, month, day);\n  return date.getFullYear() === year &&\n    date.getMonth() === month &&\n    date.getDate() === day;\n}\n\n\/\/ \u4f7f\u7528 isValidDate() \u65b9\u6cd5\u6aa2\u67e5\u65e5\u671f\u662f\u5426\u6709\u6548\nlet isValid = isValidDate(year, month, day);\n\nif (isValid) {\n  console.log('\u65e5\u671f\u6709\u6548');\n} else {\n  console.log('\u65e5\u671f\u7121\u6548');\n}\n<\/pre>\n<p>\u7e3d\u7d50\u4f86\u8aaa\uff0c\u4f7f\u7528 React.JS \u4f86\u6aa2\u67e5\u65e5\u671f\u662f\u5426\u6709\u6548\u662f\u4e00\u500b\u7c21\u55ae\u800c\u6709\u6548\u7684\u65b9\u6cd5\u3002\u4f7f\u7528 JavaScript \u4f86\u5275\u5efa\u65e5\u671f\u5c0d\u8c61\uff0c\u4e26\u4f7f\u7528 <code>isValidDate()<\/code> \u65b9\u6cd5\u4f86\u6aa2\u67e5\u65e5\u671f\u662f\u5426\u6709\u6548\uff0c\u53ef\u4ee5\u8b93\u6211\u5011\u7684\u61c9\u7528\u7a0b\u5f0f\u66f4\u52a0\u5065\u58ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2.\u4e86\u89e3\u5982\u4f55\u4f7f\u7528React.JS\u4f86\u6aa2\u67e5\u65e5\u671f\u662f\u5426\u6709\u6548\uff0c\u5b78\u7fd2\u5982\u4f55\u5229\u7528React.JS\u7684isValidDate\u51fd\u6578\u4f86\u6aa2\u67e5\u65e5\u671f\u662f\u5426\u6709\u6548\uff0c\u4ee5\u53ca\u5982\u4f55\u66f4\u6709\u6548\u5730\u6aa2\u67e5\u65e5\u671f\u7684\u6709\u6548\u6027\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[184,183],"tags":[182,181],"class_list":["post-5647","post","type-post","status-publish","format-standard","hentry","category-react","category-react-js","tag-react","tag-react-js"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1t5","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5647","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=5647"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5647\/revisions"}],"predecessor-version":[{"id":5648,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5647\/revisions\/5648"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}