Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1038603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:59:44+00:00 2026-05-16T14:59:44+00:00

I found the following code which is working well for a time sheet calculator

  • 0

I found the following code which is working well for a time sheet calculator I am using

function convertSecondsToHHMMSS(intSecondsToConvert) {
    var hours = convertHours(intSecondsToConvert);
    var minutes = getRemainingMinutes(intSecondsToConvert);
    minutes = (minutes == 60) ? "00" : minutes;
    var seconds = getRemainingSeconds(intSecondsToConvert);
    return hours+" hrs "+minutes+" mins";
}

function convertHours(intSeconds) {
    var minutes = convertMinutes(intSeconds);
    var hours = Math.floor(minutes/60);
    return hours;
}

function convertMinutes(intSeconds) {
    return Math.floor(intSeconds/60);
}

function getRemainingSeconds(intTotalSeconds) {
    return (intTotalSeconds%60);
}

function getRemainingMinutes(intSeconds) {
    var intTotalMinutes = convertMinutes(intSeconds);
    return (intTotalMinutes%60);
}

function HMStoSec1(T) { 
  var A = T.split(/\D+/) ; return (A[0]*60 + +A[1])*60 + +A[2] 
}

var time1 = HMStoSec1("10:00:00");
var time2 = HMStoSec1("12:05:00");
var diff = time2 - time1;
document.write(convertSecondsToHHMMSS(diff));

It works fine when time1 is greater than time2, if time1 is less than time2 an extra hour is subtracted eg.

var time1 = HMStoSec1("09:00:00");
var time2 = HMStoSec1("08:55:00");
var diff = time2 - time1;
document.write(convertSecondsToHHMMSS(diff)); // writes "1 hr 5 mins" instead of "0 hr 5 mins"

I think its something to do with the Math.floor in the convertHours function.

I am trying to build something that can just take hours and minutes and subtract/add time, not actually times just quantities of hours and minutes.

There must be a simpler way that sadly eludes me, any help would be greatly appreciated.

  • 1 1 Answer
  • 4 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:59:45+00:00Added an answer on May 16, 2026 at 2:59 pm

    Floor works different than most people expect for negative numbers. It returns the next integer less than the operand, so for -1.5 it will return -2. The easiest way to deal with this is just to take the absolute value (Math.abs) then add the negative sign back at the end.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Somewhere here on Stack Overflow, I had found the following code some day which
I've found the following code: https://github.com/roddi/ValidateStoreReceipt/blob/master/validatereceipt.m which loads the root certificate ('Apple Root CA')
I found the following code in my team's project: Public Shared Function isRemoteDisconnectMessage(ByRef m
Hi I found the following code from this page JQuery UI DatePicker using 2
I have the following code working nicely: $field2.on(change, #selector, function(){ $field2.load(./index.php?show-options=true, { value: $(this).val()
I found some old code which I'm not sure I understand completely. The folowing
I found the following code somewhere, but I am not understanding the code properly.
At a website , I found the following code to make a jQuery plugin:
The following code produces no suitable constructor found error. I am unable to figure
The following code can be found in the NHibernate.Id.GuidCombGenerator class. The algorithm creates sequential

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.