JavaScript 参考手册
JavaScript getUTCMonth() 方法
现在,我们将创建一个数组,使得我们上面的例子能够输出月份的名称,而不仅仅是一个数字
源代码:
点击运行 »
<p id="demo">单击按钮按照UTC显示月份名称</p> <button onclick="myFunction()">点我</button> <script> function myFunction() { var d = new Date(); var month = new Array(12); month[0] = "一月"; month[1] = "二月"; month[2] = "三月"; month[3] = "四月"; month[4] = "五月"; month[5] = "六月"; month[6] = "七月"; month[7] = "八月"; month[8] = "九月"; month[9] = "十月"; month[10] = "十一月"; month[11] = "十二月"; var x = document.getElementById("demo"); x.innerHTML = month[d.getUTCMonth()]; } </script> <p><strong>注意:</strong> 0=一月, 1=二月, 等等.</p>
运行结果:
点击运行 »