JavaScript获取当前月份并显示


使用Date()获取日期

getMonth()+1得到当前月份

var ndate = new Date();
var nmonth = ndate.getMonth()+1;

弹窗显示

alert("当前月份:"+nmonth+"月");

控制台输出

console.log("当前月份:"+nmonth+"月");

页面显示

document.write("当前月份:"+nmonth+"月");

 getMonth()的返回值是 0(1月) 到 11(12月)之间的一个整数,返回的是索引值,所以要加1。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM