Solved

Second to hours and minutes

Posted on 2004-08-28
3
247 Views
Last Modified: 2010-04-17
i am currently using this code to show time in hours and minutes from seconds. (ttime = seconds) Every 60 seconds it i make it refresh itself. It works great, the only problem that i see with it is that sometimes when its about to change from hole hours. This is what happens. It displays 02:00 then it displays (60s after) 01:00 then (60s after) 01:59. Another example would be 01:00 then 00:00 then 00:59. How can i fix this? Vb6

h = Int(Val(ttime) / 3600)
m = Int((Val(ttime) / 60) Mod 60)
If h < 10 Then
h = "0" & h
End If
If m < 10 Then
m = "0" & m
End If
0
Comment
Question by:DARKSAGES
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
DarkoLord earned 500 total points
ID: 11922518
Hi, try this (it also converts to days):

            Dim seconds As Long
            Dim d As Long 'days
            Dim h As Long 'hours
            Dim m As Long 'minutes
            Dim s As Long 'seconds

            seconds = 86401 'one day, zero hours and mins and one sec

            If (seconds >= 86400) Then
                d = seconds \ 86400
                seconds = seconds Mod 86400
            End If

            If (seconds >= 3600) Then
                h = seconds \ 3600
                seconds = seconds Mod 3600
            End If

            If (seconds >= 60) Then
                m = seconds \ 60
                seconds = seconds Mod 60
            End If
            s = seconds

Darko
0
 

Author Comment

by:DARKSAGES
ID: 11922797
Thanx, for the quick answer. That was really easy but i have something due really soon and i cant think straight.
0
 
LVL 22

Expert Comment

by:DarkoLord
ID: 11922823
You're welcome

Darko
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now