Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Javascript The getTime() Method

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 370
    Comment on it

    In Javascript , getTime() method return the numeric value ( in milliseconds ) corresponding to the time for the specified data according to universal time . Through this method you can assign a date and time to another Date Object. Basically this method is equivalent( functionally ) to the valueOf ( ) method .< br> Syntax :

    dateObj.getTime() //  There is no parameter 
    

    Return value >
    Return number of milliseconds since 1 January 1970 .
    Example ->
    1) to copy the data with the help of getTime() method

    var dob = new Date( 1994 , 09 , 17 ) ;
    var copydob = new Date () ;
    copy.setTime(dob.getTime());// in this birthday will be copied
    

    2) To measure the execution time -> We can measure the execution time by subtraction two consecutive getTime( ) calls . This can be used to calculate the executing times of some operations. Let's understand by example

    var start , end , i
    start = new Date();
    for( i = 0 ; i < 1000 ; i++){
    Math.sqrt(i);
    }
    end = new Date();
    document.write ( "operation" + (end.getTime() - start.getTime()) + "msec"); // output will come in milliseconds
    

    If you want your result in Years instead of milliseconds then you can do by dividing the milliseconds to years .

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: