目录

setUTCMilliseconds()

描述 (Description)

setUTCMilliseconds()方法根据通用时间设置指定日期的毫秒数。

语法 (Syntax)

下面给出了setUTCMilliseconds()方法的语法。

Date.setUTCMilliseconds(millisecondsValue)

参数细节 (Parameter Detail)

  • millisecondsValue - 介于0和999之间的数字,表示毫秒。

如果指定的参数超出预期范围,则setUTCMilliseconds会尝试相应地更新Date对象中的日期信息。 例如,如果使用1100作为millisecondsValue,则Date对象中存储的秒将增加1,并且100将用于毫秒。

例子 (Example)

以下示例演示了CoffeeScript中setUTCMilliseconds()方法的用法。 将此代码保存在名为date_setutcmilliseconds.coffee的文件中。

dt = new Date "February 19, 2016 23:15:00"
dt.setUTCMilliseconds 1100  
console.log dt

打开command prompt并编译.coffee文件,如下所示。

c:\> coffee -c date_setutcmilliseconds.coffee

在编译时,它为您提供以下JavaScript。

// Generated by CoffeeScript 1.10.0
(function() {
  var dt;
  dt = new Date("February 19, 2016 23:15:00");
  dt.setUTCMilliseconds(1100);
  console.log(dt);
}).call(this);

现在,再次打开command prompt ,然后运行CoffeeScript文件,如下所示。

c:\> coffee date_setutcmilliseconds.coffee

执行时,CoffeeScript文件生成以下输出。

Fri Feb 19 2016 23:15:01 GMT+0530 (India Standard Time)
↑回到顶部↑
WIKI教程 @2018