JavaScript是一门Web编程语言,用来实现网页的交互功能,它和HTML、CSS共同组成了个Web开发的基础工具集合,也是前端开发者必备的技能;学习JavaScript教程可以了解它在网页开发中的所有特性和相关概念,让我们能够更加快速的去开发Web应用。
这个getUTCHours() 方法:返回指定日期基于协调世界时UTC的小时数,该方法返回一个介于0到23之间的整数,表示自午夜起经过的小时数。
版本实现
实现于JavaScript 1.3
语法说明
getUTCHours()
执行一下示例:
以下网页文档getUTCHours()方法:返回指定日期及当前时间基于协调世界时的小时数值。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>JavaScript date object - getUTCHours() method example</title>
</head>
<body>
<h1 style="color: red">JavaScript date object : getUTCHours() method</h1>
<hr />
<script type="text/javascript">
//This is done to make the following JavaScript code compatible to XHTML. <![CDATA[
newyear2008 = new Date("January 1, 2008 11:10:00")
hor = newyear2008.getUTCHours()
document.write("The hour of "+newyear2008+" is : "+hor+"<br />")
current_date = new Date()
chor = current_date.getUTCHours()
document.write("Current hour is : "+chor+"<br />")
//]]>
</script>
</body>
</html>
执行一下支持的浏览器
IE浏览器7 | 火狐3.6 | 谷歌Chrome 7 | Safari 5.0.1 版 | Opera 10 |
Yes | Yes | Yes | Yes | Yes |
另请参阅:
上一篇:JavaScript getUTCFullYear() 方法:日期对象