PC Review


Reply
Thread Tools Rate Thread

convert time string to number of seconds

 
 
tony
Guest
Posts: n/a
 
      15th Jun 2006
Hello!

I have this method ConvStdTimeToSec here that convert format hh:mm:ss into
total number of seconds and return it.
I just wonder if there exist a metod in the .NET framework that can be used
instead.

private int ConvStdTimeToSec(string time)
{
return int.Parse(time.Substring(0,2)) * 3600 +
int.Parse(time.Substring(3,2)) * 60 + int.Parse(time.Substring(6,2));
}

//Tony


 
Reply With Quote
 
 
 
 
Tom Porterfield
Guest
Posts: n/a
 
      15th Jun 2006
tony wrote:
> Hello!
>
> I have this method ConvStdTimeToSec here that convert format hh:mm:ss into
> total number of seconds and return it.
> I just wonder if there exist a metod in the .NET framework that can be
> used instead.
>
> private int ConvStdTimeToSec(string time)
> {
> return int.Parse(time.Substring(0,2)) * 3600 +
> int.Parse(time.Substring(3,2)) * 60 + int.Parse(time.Substring(6,2));
> }


DateTime dt = DateTime.ParseExact(time, "HH:mm:ss",
System.Globalization.CultureInfo.CurrentCulture);
return dt.TimeOfDay.TotalSeconds;
--
Tom Porterfield

 
Reply With Quote
 
Barry Kelly
Guest
Posts: n/a
 
      15th Jun 2006
"tony" <(E-Mail Removed)> wrote:

> Hello!
>
> I have this method ConvStdTimeToSec here that convert format hh:mm:ss into
> total number of seconds and return it.
> I just wonder if there exist a metod in the .NET framework that can be used
> instead.
>
> private int ConvStdTimeToSec(string time)
> {
> return int.Parse(time.Substring(0,2)) * 3600 +
> int.Parse(time.Substring(3,2)) * 60 + int.Parse(time.Substring(6,2));
> }


TimeSpan.Parse(time).TotalSeconds

-- Barry

--
http://barrkel.blogspot.com/
 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      15th Jun 2006
"tony" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> I have this method ConvStdTimeToSec here that convert format hh:mm:ss into
> total number of seconds and return it.


You need the TimeOfDay.TotalSeconds method of the the DateTime class.


 
Reply With Quote
 
chanmm
Guest
Posts: n/a
 
      15th Jun 2006
Check this out:
http://msdn2.microsoft.com/en-us/library/8kb3ddd4(d=ide).aspx

chanmm

"tony" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello!
>
> I have this method ConvStdTimeToSec here that convert format hh:mm:ss into
> total number of seconds and return it.
> I just wonder if there exist a metod in the .NET framework that can be
> used
> instead.
>
> private int ConvStdTimeToSec(string time)
> {
> return int.Parse(time.Substring(0,2)) * 3600 +
> int.Parse(time.Substring(3,2)) * 60 + int.Parse(time.Substring(6,2));
> }
>
> //Tony
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert number in to time lenght, minutes and seconds? Bojan Microsoft Excel Misc 3 3rd Nov 2008 07:35 AM
Convert time in number of seconds Heera Microsoft Excel Worksheet Functions 2 22nd Aug 2008 01:29 PM
How do i convert a number of seconds to a date/time? =?Utf-8?B?TWFyZ28=?= Microsoft Excel Worksheet Functions 2 5th Jan 2005 12:09 AM
convert a number of seconds to HH:MM:SS? Steff_DK Microsoft Excel Programming 2 18th Jun 2004 10:42 PM
Need to get Time down to the 0.1 seconds in a number string jack Microsoft VB .NET 7 7th Sep 2003 10:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:20 AM.