目录

getSeconds()

描述 (Description)

getSeconds()方法根据本地时间返回指定日期的秒数。 getSeconds()返回的值是0到59之间的整数。

语法 (Syntax)

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

Date.getSeconds()

例子 (Example)

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

dt = new Date "February 19, 2016 23:15:25:22"
console.log "The seconds in the specified date is : " + dt.getSeconds()

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

c:\> coffee -c date_ getseconds.coffee

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

// Generated by CoffeeScript 1.10.0
(function() {
  var dt;
  dt = new Date("February 19, 2016 23:15:25:22");
  console.log("The seconds in the specified date is : " + dt.getSeconds());
}).call(this);

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

c:\> coffee date_ getseconds.coffee

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

The seconds in the specified date is : 25
↑回到顶部↑
WIKI教程 @2018