By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,038 Members | 1,002 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,038 IT Pros & Developers. It's quick & easy.

convert time string to number of seconds

P: n/a
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
Jun 15 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

Jun 15 '06 #2

P: n/a
"tony" <jo*****************@telia.com> 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/
Jun 15 '06 #3

P: n/a
"tony" <jo*****************@telia.com> wrote in message
news:OO**************@TK2MSFTNGP02.phx.gbl...
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.
Jun 15 '06 #4

P: n/a
Check this out:
http://msdn2.microsoft.com/en-us/lib...d4(d=ide).aspx

chanmm

"tony" <jo*****************@telia.com> wrote in message
news:OO**************@TK2MSFTNGP02.phx.gbl...
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

Jun 15 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.