<script type="text/javascript">
var curDate = new Date();
var curDateStr = curDate.getFullYear() + "-" + curDate.getMonth() + "-" + curDate.getDay();
alert(curDateStr);
</script>
var curDate = new Date();
var curDateStr = curDate.getFullYear() + "-" + curDate.getMonth() + "-" + curDate.getDay();
alert(curDateStr);
</script>
如果真是这样你就错了,不信可以运行下试试!
正确的做法请看下列代码:
<script type="text/javascript">
var curDate = new Date();
var curDateStr = curDate.getFullYear() + "-" + (curDate.getMonth() + 1) + "-" + curDate.getDate();
alert(curDateStr);
</script>
var curDate = new Date();
var curDateStr = curDate.getFullYear() + "-" + (curDate.getMonth() + 1) + "-" + curDate.getDate();
alert(curDateStr);
</script>