473,524 Members | 3,314 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting milliseconds to Days, Hours, Minutes, Seconds

I need a routine to convert milliseconds to
a traditional dd:hh:mm:ss or four separate
variables that I can display.

I am not wanting to display a date but rather
the interval between two times.

Thanks,

Deepa :-)
Jul 20 '05 #1
2 54788
Deepa wrote on 05 dec 2003 in comp.lang.javascript:
I need a routine to convert milliseconds to
a traditional dd:hh:mm:ss or four separate
variables that I can display.


<script>

function two(x) {return ((x>9)?"":"0")+x}
function three(x) {return ((x>99)?"":"0")+((x>9)?"":"0")+x}

function time(ms) {
var sec = Math.floor(ms/1000)
ms = ms % 1000
t = three(ms)

var min = Math.floor(sec/60)
sec = sec % 60
t = two(sec) + ":" + t

var hr = Math.floor(min/60)
min = min % 60
t = two(min) + ":" + t

var day = Math.floor(hr/60)
hr = hr % 60
t = two(hr) + ":" + t
t = day + ":" + t

return t
}

document.write(time(12034056070))
</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #2
Thanks!
"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn*******************@194.109.133.29...
Deepa wrote on 05 dec 2003 in comp.lang.javascript:
I need a routine to convert milliseconds to
a traditional dd:hh:mm:ss or four separate
variables that I can display.


<script>

function two(x) {return ((x>9)?"":"0")+x}
function three(x) {return ((x>99)?"":"0")+((x>9)?"":"0")+x}

function time(ms) {
var sec = Math.floor(ms/1000)
ms = ms % 1000
t = three(ms)

var min = Math.floor(sec/60)
sec = sec % 60
t = two(sec) + ":" + t

var hr = Math.floor(min/60)
min = min % 60
t = two(min) + ":" + t

var day = Math.floor(hr/60)
hr = hr % 60
t = two(hr) + ":" + t
t = day + ":" + t

return t
}

document.write(time(12034056070))
</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Jul 20 '05 #3

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

Similar topics

26
55630
by: Pravesh | last post by:
Hi: is there a way to get current system time in milliseconds... which functions and headers?? thanks pravesh
7
8999
by: Stu | last post by:
Is there a simple function call within "C" that I can use to convert number of seconds (keep in mind this may be a type longlong and has to work on UNIX and NT) into Days, months, Hours, Minutes and seconds. If anybody can provide me with an example I would be very grateful. Thanks in advance for all that answer this post.
2
3307
by: J M | last post by:
I rebooted a network device just few minutes ago and getting device-up-time value 3191. How do I convert a time elapsed in days hours minutes and seconds for above value? Example: This device has been up since 0 days 0 hours x minutes and x seconds. TIA!
19
4499
by: Ricardo Perez Lopez | last post by:
Hello everyone: I'm a PostgreSQL newbie, working now with dates, times, timestamps and intervals. I have three questions about the above: FIRST: --------
6
26426
by: Harlin Seritt | last post by:
I would like to take milliseconds and convert it to a more human-readable format like: 4 days 20 hours 10 minutes 35 seconds Is there something in the time module that can do this? I havent been able to find anything that would do it. Thanks,
2
10821
by: Harlin Seritt | last post by:
How can I take a time given in milliseconds (I am doing this for an uptime script) and convert it to human-friendly time i.e. "4 days, 2 hours, 25 minutes, 10 seonds."? Is there a function from the time module that can do this? Thanks, Harlin Seritt
1
3694
by: maywj1 | last post by:
I looking for some help in completing the code below for use within an access app. I currently attach my database to an application which stores a swimmer's time. The problem I'm having is that the the swimmer's time within the table displays 67.62 seconds. The code below modifies this to read 00:01:08:00. I'm hoping someone could help...
3
28460
by: Mark | last post by:
I'd like to compare two datetime values in milliseconds. The datetime.compare method appears to show only seconds. Milliseconds of a datetime are available as a property of each datetime, but I am assuming there is an easier way than comparing the milliseconds, seconds, minutes, hours, days, etc, individually to generate the difference. ...
4
6706
by: Deniz Dogan | last post by:
Hello. I need help with a small problem I'm having. I want to make a function which takes an integer representing some time in milliseconds and returns the same time but formatted as "hours:minutes:seconds,milliseconds" with leading zeros whenever possible. E.g. I input 185804 to the function and it returns 00:03:05,804. The function I'm...
0
7326
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7633
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7216
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7596
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5771
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5165
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4810
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3308
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
535
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.