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 941999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:12:11+00:00 2026-05-15T22:12:11+00:00

I have the time stored as a fraction (done so it can be displayed

  • 0

I have the time stored as a fraction (done so it can be displayed on a graph), e.g. 15.5 is 3.30pm and 23.25 is 11.15pm. I need to turn those numbers into strings in the format HH:MM:SS. Is there a simple way of doing this?

  • 1 1 Answer
  • 0 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-15T22:12:11+00:00Added an answer on May 15, 2026 at 10:12 pm

    Something like this ?

    var fraction = 14.5;
    var hours = Math.floor(fraction); // extract the hours (in 24 hour format)
    var mins = 60 * (fraction - hours); // calculate the minutes
    t = new Date(); // create a date/time object
    
    t.setHours(hours); // set the hours
    t.setMinutes(mins); // set the mins
    console.log(t.toTimeString()); //show it

    or completely manual

    var fraction = 14.5;
    var hours = Math.floor(fraction);
    var mins = 60 * (fraction - hours);
    var ampm = ((fraction % 24) < 12) ? 'am' : 'pm';
    
    formatted = ('0' + hours % 12).substr(-2) + ':' + ('0' + mins).substr(-2) + ':00 ' + ampm;
    console.log(formatted);

    Update

    And a version with seconds as well..

    var fraction = 14.33;
    var hours = Math.floor(fraction);
    var allseconds = 3600 * (fraction - hours);
    var minutes = Math.floor(allseconds / 60);
    var seconds = Math.floor(allseconds % 60);
    var ampm = ((fraction % 24) < 12) ? 'am' : 'pm';
    
    formatted = ('0' + hours % 12).substr(-2) + ':' + ('0' + minutes).substr(-2) + ':' + ('0' + seconds).substr(-2) + ' ' + ampm;
    console.log(formatted);
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have big number, time (micro seconds) stored in two 32bit variables. I need
I have a table containing view/click records. The time is stored in a unix
I have a Date array which stored dates and time in its respective positions
I have a String that represents a time value and is stored in the
I have a stored time value which is of the format H:mm:ss . The
I have a time value being stored in a database as a varchar(4) and
I have a (date time) stored in database in this format 2011-10-12 02:01:24 when
I have high scores (name, score, time) stored in a single file and I
I have a time stored as a decimal(9,2) column in an sql-server 2005 database.
I have date and time stored in my database and I don't want to

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.