Home  >  Article  >  Web Front-end  >  Detailed explanation of the use of setSeconds() method in JavaScript_Basic knowledge

Detailed explanation of the use of setSeconds() method in JavaScript_Basic knowledge

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

The javascript Date.setSeconds() method specifies the date according to the set seconds of the local time.
Grammar

Date.setSeconds(secondsValue[, msValue])

Note: The data inside and outside the brackets are optional

Here are the details of the parameters:

  • secondsValue: an integer between 0 and 59.
  • msValue: A number between 0 and 999, representing milliseconds.

If the msValue parameter is not specified, the value returned from the method using getMilliseconds is used. If the specified argument is outside the expected range, calling setSeconds attempts to update the Date object's latest information accordingly. For example, if you use secondsValue with a value of 100, the minutes stored in the date object will be increased by 1, and 40 will be used for seconds.
Return value:

  • NA

Example:

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

This will produce the following results:

Thu Aug 28 23:31:20 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