Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][tlug] [OT] Subtracting two times in JavaScript
- Date: Sat, 20 Mar 2010 22:42:21 +0900
- From: Dave M G <dave@example.com>
- Subject: [tlug] [OT] Subtracting two times in JavaScript
- User-agent: Thunderbird 2.0.0.24 (X11/20100317)
TLUG, I know this isn't a JavaScript list, but the advantage you guys have over other JavaScript lists I've posted to is that you actually respond. So I hope this new question won't be contributing too much noise. All I'm trying to do is take two times, subtract one from the other, and get the difference back in hours and minutes (formatted like this - 0:00). I've gone round and round trying to convert times back and forth from Unix time, and using JavaScripts Date() functions which theoretically allow you to subtract times directly... In the following example, "this.timeStamp" is a Unix time stamp, and I'm confident that it's set right because it's working in an another function. (Of course, I've been wrong before.) The times I'm getting back from this code is crazy. Like, when I expect the different to be about an hour (1:00), it comes out as 9:59. Or sometimes the format will be off, like 9:5 So I'm sure I've got my conversions off, but I've been over it again and again, and don't see why this isn't working. Well, I mean, I'm using code of the internet, so I'm going on the assumption that the pages I got the code from knew what they were doing. If anyone can, might they tell me why I'm not getting a correct hours and minutes difference between these two times. endTime = new Date(this.timeStamp); currTime = new Date(); diff = new Date(endTime.getTime() - currTime.getTime()); var hours = diff.getHours(); var minutes = diff.getMinutes(); if (minutes.length == 1) { minutes = "0" + minutes; } remainTime = hours + ":" + minutes; return remainTime; Any advice would be much appreciated. -- Dave M G
- Follow-Ups:
- Re: [tlug] [OT] Subtracting two times in JavaScript
- From: Edmund Edgar
- Re: [tlug] [OT] Subtracting two times in JavaScript
- From: Godwin Stewart
- Re: [tlug] [OT] Subtracting two times in JavaScript
- From: Lewske Wada
- Re: [tlug] [OT] Subtracting two times in JavaScript
- From: Fredric Fredricson
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] Changing a file server from XP to Ubuntu
- Next by Date: Re: [tlug] [OT] Subtracting two times in JavaScript
- Previous by thread: [tlug] Amazon Web Services Study Group meeting, April 6 19:00
- Next by thread: Re: [tlug] [OT] Subtracting two times in JavaScript
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links