--- title: Date.prototype.setTime() slug: Web/JavaScript/Reference/Global_Objects/Date/setTime translation_of: Web/JavaScript/Reference/Global_Objects/Date/setTime ---
setTime()
方法以一个表示从1970-1-1 00:00:00 UTC计时的毫秒数为来为 Date
对象设置时间。
dateObj.setTime(timeValue)
timeValue
使用 setTime
方法用来把一个日期时间赋值给另一个 Date
对象。
setTime
theBigDay = new Date("July 1, 1999"); sameAsBigDay = new Date(); sameAsBigDay.setTime(theBigDay.getTime());
规范版本 | 规范状态 | 注解 |
---|---|---|
ECMAScript 1st Edition. Implemented in JavaScript 1.0 | Standard | Initial definition. |
{{SpecName('ES5.1', '#sec-15.9.5.27', 'Date.prototype.setTime')}} | {{Spec2('ES5.1')}} | |
{{SpecName('ES6', '#sec-date.prototype.settime', 'Date.prototype.setTime')}} | {{Spec2('ES6')}} |
{{Compat("javascript.builtins.Date.setTime")}}