--- title: Date.prototype.setUTCMonth() slug: Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth translation_of: Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth --- <div>{{JSRef}}</div> <p><strong><code>setUTCMonth()方法根据通用的时间来设置一个准确的月份</code></strong></p> <div>{{EmbedInteractiveExample("pages/js/date-setutcmonth.html")}}</div> <h2 id="语法">语法</h2> <pre class="syntaxbox"><code><var>dateObj</var>.setUTCMonth(<var>monthValue</var>[, <var>dayValue</var>])</code></pre> <h3 id="参数">参数</h3> <dl> <dt><code>monthValue</code></dt> <dd>一个0-11的整数,代表1月到12月。</dd> <dt><code>dayValue</code></dt> <dd>可选参数:一个1-31的整数,代表一个月的天数。</dd> </dl> <h3 id="返回值">返回值</h3> <p>这个数值是从1970年1月1号 00:00:00到当前时间的毫秒数(国际通用时间)</p> <h2 id="描述">描述</h2> <p>如果你没有明确书写<code>dayValue</code> 这个参数,那么就会从{{jsxref("Date.prototype.getUTCDate()", "getUTCDate()")}} 方法返回对应的数值.</p> <p>如果你写了一个超过在规定的范围内的参数. <code>setUTCMonth()就会试图相应的更新时间信息在Data对象中。例如,如果你用15作为</code>monthValue的值,那么年份就会加1,并且月份会变成3.(15=12+3)</p> <h2 id="示例">示例</h2> <h3 id="使用_setUTCMonth()">使用 <code>setUTCMonth()</code></h3> <pre class="brush: js">var theBigDay = new Date(); theBigDay.setUTCMonth(11); </pre> <h2 id="规范">规范</h2> <table class="standard-table"> <tbody> <tr> <th scope="col">规范</th> <th scope="col">状态</th> <th scope="col">注释</th> </tr> <tr> <td>{{SpecName('ES1')}}</td> <td>{{Spec2('ES1')}}</td> <td>最初定义并使用在javascript 1.3版本中</td> </tr> <tr> <td>{{SpecName('ES5.1', '#sec-15.9.5.39', 'Date.prototype.setUTCMonth')}}</td> <td>{{Spec2('ES5.1')}}</td> <td> </td> </tr> <tr> <td>{{SpecName('ES6', '#sec-date.prototype.setutcmonth', 'Date.prototype.setUTCMonth')}}</td> <td>{{Spec2('ES6')}}</td> <td> </td> </tr> <tr> <td>{{SpecName('ESDraft', '#sec-date.prototype.setutcmonth', 'Date.prototype.setUTCMonth')}}</td> <td>{{Spec2('ESDraft')}}</td> <td> </td> </tr> </tbody> </table> <h2 id="浏览器兼容性">浏览器兼容性</h2> <div> <p>{{Compat("javascript.builtins.Date.setUTCMonth")}}</p> </div> <h2 id="更多">更多</h2> <ul> <li>{{jsxref("Date.prototype.getUTCMonth()")}}</li> <li>{{jsxref("Date.prototype.setMonth()")}}</li> </ul>