為什么輸出的日期中月份和日數(shù)不對?
<script type="text/javascript">
var mydate = new Date
document.write("年份:"+mydate.getFullYear()+'<br>' );
document.write("月份:"+mydate.getMonth()+'<br>');
document.write("日期:"+mydate.getDay()+'<br>');
document.write("時(shí):"+mydate.getHours()+'<br>');
document.write("分:"+mydate.getMinutes()+'<br>');
document.write("秒:"+mydate.getSeconds()+'<br>');
</script>
輸出的結(jié)果是:
2016年 5月 5日
實(shí)際結(jié)果是2016年 6月 17 日
為什么結(jié)果不對?
2016-06-17
在js中用getMonth()+1才是我們當(dāng)前的月份,應(yīng)為老外一般都是從0開始計(jì)算的因此比我們少了1
2016-09-12
document.write("日期:"+mydate.getDay()+'<br>');
這里是錯(cuò)的;getDay()是獲取星期的函數(shù);日期是getDate();
英文都是這樣說的:
what's the date today? ?今天幾號?
what day is today? ?今天星期幾?
編程,英語也還是得多多學(xué)習(xí),對以后學(xué)習(xí)更多有幫助。
2016-07-03
我覺得說的不對
Array的索引正常都是從零開始 我的就沒有問題 你看你給變量賦值的地方
var mydate=new Date();你缺少了一個(gè)括號 JS強(qiáng)調(diào)嚴(yán)謹(jǐn)性