内容目录
setUTCSeconds()函数用于基于UTC时间设置当前Date对象中的秒值。也就是"年月日 时分秒"中"秒"的数值。setUTCSeconds()函数还可同时设置毫秒值。
该函数属于Date对象,所有主流浏览器均支持该函数。
语法
date.setUTCSeconds( seconds[, milliseconds ] )
参数
| 参数 | 描述 |
|---|---|
| seconds | Number类型指定的秒值。 |
| milliseconds | 可选/Number类型指定的毫秒值。 |
setUTCSeconds()函数的所有参数都可以超出常规取值范围。例如:参数seconds可以超出常规的0 ~ 59的取值范围;参数milliseconds可以超出常规的0 ~ 999的取值范围;并且都可以为负数。Date对象内部会自动计算并转换为相应的时间。
返回值
setUTCSeconds()函数没有返回值(或者说,返回值为undefined)。
示例&说明
// 当前运行环境的时区为 UTC +8
//定义一个本地时间的Date对象"2013-05-15 00:00:00 132"
var date = new Date(2013, 4, 15, 0, 0, 0, 132);
document.writeln( date.toLocaleString() + " " + date.getMilliseconds() ); // 2013年5月15日 0:00:00 132
date.setUTCSeconds(36);
document.writeln( date.toLocaleString() + " " + date.getMilliseconds() ); // 2013年5月15日 0:00:36 132
date.setUTCSeconds(-6000);
document.writeln( date.toLocaleString() + " " + date.getMilliseconds() ); // 2013年5月14日 22:20:00 132
date.setUTCSeconds(120, -5);
document.writeln( date.toLocaleString() + " " + date.getMilliseconds() ); // 2013年5月14日 22:21:59 995

0 条评论
撰写评论