目录

getTimezoneOffset()

描述 (Description)

getTimezoneOffset()方法返回当前语言环境的时区偏移量(以分钟为单位)。 时区偏移是差异的分钟,格林威治标准时间(GMT)是相对于您当地时间的。

例如,如果您的时区为GMT + 10,则会返回-600。 夏令时可防止此值成为常量。

语法 (Syntax)

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

Date. getTimezoneOffset()

例子 (Example)

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

dt = new Date "February 19, 2016 23:15:25:22"
console.log "The time zone offset value of the specified date is : " + dt.getTimezoneOffset()

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

c:\> coffee -c date_ gettimezoneoffset.coffee

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

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

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

c:\> coffee date_ gettimezoneoffset.coffee

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

The time zone offset value of the specified date is : -330
↑回到顶部↑
WIKI教程 @2018