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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:22:28+00:00 2026-06-17T13:22:28+00:00

With this script getFormattedTime = function (fourDigitTime){ var hours24 = parseInt(fourDigitTime.substring(0,2)); var hours =

  • 0

With this script

getFormattedTime = function (fourDigitTime){
var hours24 = parseInt(fourDigitTime.substring(0,2));
var hours = ((hours24 + 11) % 12) + 1;
var amPm = hours24 > 11 ? 'pm' : 'am';
var minutes = fourDigitTime.substring(2);

return hours + ':' + minutes + amPm;
};

I can change 4 digit time to normal clock time (there is a problem with 0930 though..)

And with this

$("body").html($("body").html().replace(/1135/g,'11:35am'));

To replace any occurange of 1135 in my page.

However, in my page, I have a list of time in tables. I need to convert them e.g.

Class starts at 1700, please be there by 1630 and sign in by 1645.

It should translate into

Class starts at 05:00pm, please be there by 04:30pm and sign in by 04:45pm.
  • 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-06-17T13:22:29+00:00Added an answer on June 17, 2026 at 1:22 pm

    Assuming the only digits displayed in the text are the times you can use:

    var txt = 'Class starts at 0845, please be there by 1630 and sign in by 1645.'
    
    getFormattedTime = function (fourDigitTime) {
        var hours24 = parseInt(fourDigitTime.substring(0, 2),10);
        var hours = ((hours24 + 11) % 12) + 1;
        var amPm = hours24 > 11 ? 'pm' : 'am';
        var minutes = fourDigitTime.substring(2);
    
        return hours + ':' + minutes + amPm;
    };
    /* replace numeric entities*/
    var newTxt = txt.replace(/(\d+)/g, function (match) {
        return getFormattedTime(match)
    })
    $('body').html(newTxt);
    

    DEMO : http://jsfiddle.net/q6HC9/1

    EDIT: Wrapping times in a tag would greatly simplify situation. Wrap all military times in a span with a common class and then use the html() method

    <span class="mil_time">0845</span>
    
    getFormattedTime = function (fourDigitTime) {
        /* make sure add radix*/
        var hours24 = parseInt(fourDigitTime.substring(0, 2),10);
        var hours = ((hours24 + 11) % 12) + 1;
        var amPm = hours24 > 11 ? 'pm' : 'am';
        var minutes = fourDigitTime.substring(2);
    
        return hours + ':' + minutes + amPm;
    };
    /* find all spans and replace their content*/
    $('span.mil_time').html(function( i, oldHtml){
       return getFormattedTime(oldHtml);
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this script in two different servers: function curlGetFileInfo($url, $cookies=default){ global $_config; $ch
i use this script to load content of some div, inside another div: $(function()
This script works perfectly in all the browsers, except Google Chrome. $(document).ready(function(){ $(.banners-anim img).each(function(){
This script is an open source tutorial on Net tuts+ but I can't figure
This script shows and positions a div like: function myfunction() { obj.style.visibility = visible;
This script should accept a set of search terms and return a formatted URL
This script doesn't work.. Where is the error? With .onload it's OK $(document).ready(function() {
This script is analysing face reactions with Face.com API. for some reason pygame can't
this script file name 1sr and i can work in terminal . 1sr i
this script is developed to support only IE I have this: var result =

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.