setDate()

优质
小牛编辑
117浏览
2023-12-01

描述 (Description)

setDate()方法根据本地时间设置指定日期的月中某天。

语法 (Syntax)

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

Date.setDate dayValue 

例子 (Example)

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

dt = new Date "Aug 28, 2008 23:30:00"
dt.setDate 24
console.log dt

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

c:\> coffee -c date_setdate.coffee 

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

// Generated by CoffeeScript 1.10.0
(function() {
  var dt;
  dt = new Date("Aug 28, 2008 23:30:00");
  dt.setDate(24);
  console.log(dt);
}).call(this);

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

c:\> coffee date_setdate.coffee

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

Sun Aug 24 2008 23:30:00 GMT+0530 (India Standard Time)