Converting int seconds to datetime or formated string

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
DateTime dt = new DateTime(year, month, day, 0, 0, 0);

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

Is that what you mean?
 
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);
 
Back
Top