Solved

Second to hours and minutes

Posted on 2004-08-28
3
246 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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 …

759 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

18 Experts available now in Live!

Get 1:1 Help Now