Home  >  Article  >  Web Front-end  >  简介JavaScript中的setHours()方法的使用_基础知识

简介JavaScript中的setHours()方法的使用_基础知识

WBOY
WBOYOriginal
2016-05-16 15:55:371725browse

 javascript Date.setHours()方法按照本地时间设置小时在指定的日期。
语法

Date.setHours(hoursValue[, minutesValue[, 
                 secondsValue[, msValue]]])

注:括号内的参数是可选的

下面是参数的详细信息:

  •     hoursValue : 0到23之间的整数,代表小时
  •     minutesValue :0到59之间的整数,代表分钟
  •     secondsValue : 0到59之间的整数,代表秒。如果指定secondsValue参数,则还必须指定minutesValue
  •     msValue : 一个数字0和999之间,代表毫秒。如果指定msValue参数,则还必须指定minutesValue和secondsValue

如果不指定 minutesValue,secondsValue 和 msValue 参数,使用getUTCMinutes,getUTCSeconds 和 getMilliseconds方法返回的值
返回值:

  • NA

例子:

<html>
<head>
<title>JavaScript setHours Method</title>
</head>
<body>
<script type="text/javascript">
  var dt = new Date( "Aug 28, 2008 23:30:00" );
  dt.setHours( 02 );
  document.write( dt ); 
</script>
</body>
</html>

这将产生以下结果:

Thu Aug 28 02:30:00 UTC+0530 2008 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn