您的浏览器过于古老 & 陈旧。为了更好的访问体验, 请 升级你的浏览器
Ready 发布于2014年08月08日 08:07

原创 JavaScript Date.getUTCHours() 函数详解

2136 次浏览 读完需要≈ 3 分钟

内容目录

getUTCHours()函数用于使用UTC时间返回当前Date对象中的小时值。也就是"年月日 时分秒"中"时"的数值。

例如:"2013年7月15日 18:12:59",就返回18;"2014年7月7日 00:23:42",就返回0。(以上时间均基于UTC时间)。

该函数属于Date对象,所有主流浏览器均支持该函数

语法

date.getUTCHours( )

返回值

getUTCHours()函数的返回值为Number类型,返回当前Date对象基于UTC时间的小时值。该值介于 [0, 23] 之间。

示例&说明

// 当前运行环境的时区为 UTC+8

//定义一个当前时间的Date对象(2014-08-07 20:14:32)
var date = new Date();
document.writeln( date.getUTCHours() ); // 12

// 定义一个"2001-06-30 12:11:59 230"的Date对象
var date2 = new Date(2001, 5, 30, 12, 11, 59, 230);
document.writeln( date2.getUTCHours() ); // 4

// 定义一个"2008-08-08 00:56:59"的Date对象
var date3 = new Date(2008, 7, 8, 0, 56, 59);
// 此时的UTC时间为"2008-08-07 16:56:59"
document.writeln( date3.getUTCHours() ); // 16

运行代码

  • CodePlayer技术交流群1
  • CodePlayer技术交流群2

0 条评论

撰写评论

打开导航菜单