Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
is there any possibility to use timer only with seconds....
for example standard timer is this : ("{0:hh:mm:ss tt} that mean 00:00:00
h m s



I want to have example only second ex " 00 "

thnx ??
Posted
Comments
Sergey Alexandrovich Kryukov 7-May-12 16:28pm    
There are at least three different types of timer (not counting Stopwatch). And all of them allow to specify seconds, of course. Which one do you want to use? And please, always specify a fully-qualified type names -- who would like to do a guesswork.
I noted you often receive complains about incorrect, uncertain or poorly specified questions. Why would you keep doing it? After all, do you want some help or not?
--SA
Sergey Alexandrovich Kryukov 7-May-12 16:28pm    
Reason for my vote of 1
Yet another question without complete specification.
--SA

You need a datetime or a timespan ?

C#
//datetime : parenthesys are unnecessary, just to underline that you can put a datetime in them.
var s = (DateTime.Now).Second 

// timespan : time span of 1h : 2m : 3, as before parenthesys are unnecessary, you can put a datediff (DateTime.Now.Substract(yourDate))
var s = (new TimeSpan(1, 2, 3)).TotalSeconds;
 
Share this answer
 
I think you might be confusing objects. The timer is used for intervals which is set via the Interval Property[^]

This property is in milliseconds so if you want to set it using seconds just multiply your seconds value by 1000.


If it is the stopwatch you are asking about then just use the ElapsedTime which is a time span and access the total seconds (as katananesei has said).

C#
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

sw.Start();
//Do what you are trying to capture process time on
sw.Stop();
var seconds = sw.Elapsed.TotalSeconds;
 
Share this answer
 
v2

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