Click here to Skip to main content
11,416,531 members (67,257 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 7-May-12 9:20am
h7h7h7444
Comments
SAKryukov at 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
SAKryukov at 7-May-12 16:28pm
   
Reason for my vote of 1
Yet another question without complete specification.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need a datetime or a timespan ?

//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;
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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).

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;
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,270
1 OriginalGriff 7,512
2 Maciej Los 3,710
3 Abhinav S 3,324
4 Peter Leow 3,084


Advertise | Privacy | Mobile
Web01 | 2.8.150427.4 | Last Updated 7 May 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100