473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

seconds to time HH:MM

in my db i have the time as seconds, 3600, 1800, etc. how can i convert that
to the actual time and display it as 1:00 AM, etc?

thx
Nov 16 '05 #1
3 3504
Barney wrote:
in my db i have the time as seconds, 3600, 1800, etc. how can i convert that
to the actual time and display it as 1:00 AM, etc?

thx

Here's the function i use to show time in HH:MM:SS by given time in seconds
It doesn't show AM/PM and doesn't detect next day (HH > 24), just because i didn't use that.
But it's easy to add

public string FormatTime(int ASecTime)
{
string res = "";
int hr = ASecTime / 3600;
int min = (ASecTime % 3600) / 60;
int sec = ASecTime % 60;

res += (hr >= 10)? hr.ToString() : "0" + hr.ToString();
res += ":";
res += (min >= 10)? min.ToString() : "0" + min.ToString();
res += ":";
res += (sec >= 10)? sec.ToString() : "0" + sec.ToString();
return res;
}
Hope it helps,
Andrey
Nov 16 '05 #2
If you mean that the time is stored as seconds from midnight, you could
use something like this:

using System;

class App
{
static void Main()
{
DateTime dt = DateTime.Today;
dt = dt.AddSeconds(1800);
Console.WriteLine(dt.ToShortTimeString());
}
}

Regards,
Joakim

Barney wrote:
in my db i have the time as seconds, 3600, 1800, etc. how can i convert that
to the actual time and display it as 1:00 AM, etc?

thx

Nov 16 '05 #3

Use the DateTime(int, int, int) constructor. Someone showed a way of doing
this using the fromseconds method, but I don't know that off the top of my
head.

Chris

"MuZZy" <le*******@yahoo.com> wrote in message
news:7O********************@rcn.net...
Barney wrote:
in my db i have the time as seconds, 3600, 1800, etc. how can i convert
that to the actual time and display it as 1:00 AM, etc?

thx

Here's the function i use to show time in HH:MM:SS by given time in
seconds
It doesn't show AM/PM and doesn't detect next day (HH > 24), just because
i didn't use that.
But it's easy to add

public string FormatTime(int ASecTime)
{
string res = "";
int hr = ASecTime / 3600;
int min = (ASecTime % 3600) / 60;
int sec = ASecTime % 60;

res += (hr >= 10)? hr.ToString() : "0" + hr.ToString();
res += ":";
res += (min >= 10)? min.ToString() : "0" + min.ToString();
res += ":";
res += (sec >= 10)? sec.ToString() : "0" + sec.ToString();
return res;
}
Hope it helps,
Andrey

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: hikums | last post by:
Does anyone have a function to convert duration in seconds to a format hh:mm:ss Thanks.
6
by: Able | last post by:
Dear friends I need to format seconds as hh:mm:ss. I see a lot of coding transforming seconds to hh:mm:ss. Somebody know a short way? Regards Able
14
by: Michael Barrido | last post by:
I have this for example: Dim iSeconds as int32 = 3600 '3600 seconds is one hour How do i convert it to "01:00:00" ? Please help. Thanks in advance!
15
by: Jay Tee | last post by:
Hi, I have some code that does, essentially, the following: - gather information on tens of thousands of items (in this case, jobs running on a compute cluster) - store the information as a...
1
by: Vishal Bhargava | last post by:
Is there an inbuilt library in Python which you can use to convert time in seconds to hh:mm:ss format? Thanks, Vishal
1
by: unknown66 | last post by:
hello, I have a time value in unix time that I would like to convert into a time format of hh:mm:ss:ms. For example, I have this number, 1172234138451, that I would like to be in the hh:mm:ss:ms...
1
seshu
by: seshu | last post by:
Hi every body to morning my cousine has show his application and also his live db in that to sav the length of all the voice files he has saved in time format ie he took the datatype of time now i...
1
seshu
by: seshu | last post by:
Hi every body to morning my cousine has show his application and also his live db in that to sav the length of all the voice files he has saved in time format ie he took the datatype of time now i...
1
by: emajka21 | last post by:
I am using Visual Studios 2005 with C#. I have a time field that is stored in seconds. I want to display it as hours:minutes:seconds in a repeater field. I know I can use division and mod's to get...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.