Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

I am new in Asp.net MVC, and currently am doing a project in MVC 3 . And i need to show the Elapsed Time when a div is load. I need the client side Elapsed time.

Is there any option for showing Client side Elapsed time in Visual Studio 2010 (MV3)
or have to use Jquery.?

Can you please help me.....


Thanks and Regards,

Dileep
Posted
Updated 24-Jul-12 21:15pm
v2

1 solution

XML
<script>
var seconds = null;
var ticker = null;

function startTimer( )
{
    seconds = -1;
    ticker = setInterval("tick( )", 1000);
    tick( );
}

function tick( )
{
    ++seconds;
    var secs = seconds;
    var hrs = Math.floor( secs / 3600 );
    secs %= 3600;
    var mns = Math.floor( secs / 60 );
    secs %= 60;
    var pretty = ( hrs < 10 ? "0" : "" ) + hrs
               + ":" + ( mns < 10 ? "0" : "" ) + mns
               + ":" + ( secs < 10 ? "0" : "" ) + secs;
    document.getElementById("ELAPSED").innerHTML = pretty;
}
</script>
<body onLoad="startTimer( )">
...
The elapsed time is now <span id="ELAPSED"></span>
...
</body>
 
Share this answer
 
Comments
dilzz 25-Jul-12 3:27am    
Thank you sir... Its working.....


Thanks and Regards

Dileep
Raghunatha_Reddy_S 25-Jul-12 3:31am    
:-)
dilzz 25-Jul-12 3:32am    
Sir i have another doubt, how can we use this code to show multiple elapsed time in a page in differed areas..

I mean we have four <div> tags. and i have to show the Time Elapsed in these four <div> tags.

Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900