Converting int seconds to datetime or formated string

G

Guest

I am pulling an integer value of the amount of seconds since 12:00 am from a
SQL Server DB. I want to convert this integer into a formated string or
datetime to display a legible time of day. Are there any built in methods in
the .NET framework that will accomplish this. If not, any other suggestion
about creating a method to do this would be appretiated.
Thanks
 
A

Arran Pearce

DateTime dt = new DateTime(year, month, day, 0, 0, 0);

dt.Add(new TimeSpan(0,0,numberOfSecs);

Is that what you mean?
 
C

Chris Priede

Pat said:
I am pulling an integer value of the amount of seconds
since 12:00 am

Since you didn't specify what date, I am going to assume it is always from
12:00am today.
I want to convert this integer into a formated string or
datetime to display a legible time of day.

A few ideas to get you started:


DateTime foo = DateTime.Now.Date.AddSeconds(seconds);

string foo = string.Format("{0:00}:{1:00}", seconds / 3600, seconds % 3600 /
60);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top