Click here to Skip to main content
13,592,561 members
Rate this:
Please Sign up or sign in to vote.
See more:
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 8:20am
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?
Reason for my vote of 1
Yet another question without complete specification.
Rate this: bad
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;
Rate this: bad
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();

//Do what you are trying to capture process time on
var seconds = sw.Elapsed.TotalSeconds;

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web04-2016 | 2.8.180618.1 | Last Updated 7 May 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

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