javascript手冊-s2[1]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 longj 的 blog

settime method

sets the value of a date object.

语法

dateobjectname.settime(timevalue) 

dateobjectname is either the name of a date object or a property of an existing object.
timevalue is an integer or a property of an existing object, representing the number of milliseconds since the epoch (1 january 1970 00:00:00).

方法

date

描述

use the settime method to help assign a date and time to another date object.

例子

thebigday = new date("july 1, 1999")
sameasbigday = new date()
sameasbigday.settime(thebigday.gettime())

相关

  • gettime method

    settimeout method

    evaluates an expression after a specified number of milliseconds have elapsed.

    语法

    timeoutid=settimeout(expression, msec)

    timeoutid is an identifier that is used only to cancel the evaluation with the cleartimeout method.
    expression is a string expression or a property of an existing object.
    msec is a numeric value, numeric string, or a property of an existing object in millisecond units.

    方法

    frame, window

    描述

    the settimeout method evaluates an expression after a specified amount of time. it does not evaluate the expression repeatedly. for example, if a settimeout method specifies 5 seconds, the expression is evaluated after 5 seconds, not every 5 seconds.

    例子

    example 1. the following example displays an alert message 5 seconds (5,000 milliseconds) after the user clicks a button. if the user clicks the second button before the alert message is displayed, the timeout is canceled and the alert does not display.

    <script language="javascript"> function displayalert() { alert("5 seconds have elapsed since the button was clicked.") } </script> <body> <form> click the button on the left for a reminder in 5 seconds; click the button on the right to cancel the reminder before it is displayed. <p> <input type="button" value="5-second reminder" name="remind_button" onclick="timerid=settimeout('displayalert()',5000)"> <input type="button" value="clear the 5-second reminder" name="remind_disable_button" onclick="cleartimeout(timerid)"> </form> </body>

    example 2. the following example displays the current time in a text object. the showtime() function, which is called recursively, uses the settimeout method update the time every second.

    <head> <script language="javascript"> <!-- var timerid = null var timerrunning = false function stopclock(){ if(timerrunning) cleartimeout(timerid) timerrunning = false } function startclock(){ // make sure the clock is stopped stopclock() showtime() } function showtime(){ var now = new date() var hours = now.gethours() var minutes = now.getminutes() var seconds = now.getseconds() var timevalue = "" + ((hours > 12) ? hours - 12 : hours) timevalue += ((minutes < 10) ? ":0" : ":") + minutes timevalue += ((seconds < 10) ? ":0" : ":") + seconds timevalue += (hours >= 12) ? " p.m." : " a.m." document.clock.face.value = timevalue timerid = settimeout("showtime()",1000) timerrunning = true } //--> </script> </head> <body onload="startclock()"> <form name="clock" onsubmit="0"> <input type="text" name="face" size=12 value =""> </form> </body>

    相关

  • cleartimeout method

    setyear method

    sets the year for a specified date.

    语法

    dateobjectname.setyear(yearvalue)

    dateobjectname is either the name of a date object or a property of an existing object.

  • 本文关键:javascript
      相关方案
    Google
     

    本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

    go top