getTime() difference

Discussion in 'JavaScript' started by dhina.techno, Oct 30, 2007.

  1. #1
    Hi,
    Please help me in getting the difference between the two timestamps.

    Var d = new Date()

    Var timestamp1 = d.getTime()

    Var timestamp2 = d.getTime()
    Var timediff = timestamp2 – timestamp1

    Alert(timediff)

    When I execute this code, I get a NaN

    What’s going wrong with this code? Kindly help me with this problem.

    Thanks,
    Dhina
     
    dhina.techno, Oct 30, 2007 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    You should use parenthesis and var is lowercase.
    Try this, is working for me:
    
    var d = new Date();
    var timestamp1 = d.getTime()
    var timestamp2 = d.getTime();
    var timediff = timestamp2 - timestamp1;
    alert(timediff);
    
    Code (markup):
     
    ajsa52, Oct 31, 2007 IP