Home > Web Front-end > JS Tutorial > body text

JavaScript gets the last day of a certain month in a certain year with screenshot_javascript skills

WBOY
Release: 2016-05-16 16:43:29
Original
1110 people have browsed it

1. Implement source code

<!DOCTYPE html> 
<!-- 
To change this license header, choose License Headers in Project Properties. 
To change this template file, choose Tools | Templates 
and open the template in the editor. 
--> 
<html> 
<head> 
<title>JavaScript获取某年某月的最后一天</title> 
<meta charset="UTF-8"> 
<meta name="viewport" content="width=device-width"> 
<script type="text/javascript"> 
/** 
* 获取某年某月的最后一天 
*/ 
function getLastDayOfMonth(year,month) 
{ 
//获取本年本月的第一天日期 
var date = new Date(year,month-1,'01'); 
//设置日期 
date.setDate(1); 
//设置月份 
date.setMonth(date.getMonth() + 1); 
//获取本月的最后一天 
cdate = new Date(date.getTime() - 1000*60*60*24); 
//打印某年某月的最后一天 
alert(cdate.getFullYear()+"年"+(Number(cdate.getMonth())+1)+"月最后一天的日期:"+cdate.getDate()+"日"); 
//返回结果 
return cdate.getDate(); 
} 
</script> 
</head> 
<body> 
<input type="button" value="获取某年某月的最后一天" onclick="getLastDayOfMonth(2014,6)"/> 
</body> 
</html>
Copy after login

2. Realize results

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!