要在JavaScript中获取当月的第一个和最后一个日期,您可以尝试运行以下代码-
<html> <head> <title>JavaScript Dates</title> </head> <body> <script> var date = new Date(); document.write("Current Date: " + date ); var firstDay = new Date(date.getFullYear(), date.getMonth(), 1); document.write("<br>"+firstDay); var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0); document.write("<br>"+lastDay); </script> </body> </html>