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

  • Home
  • SEARCH
  • 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 8312161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:04:11+00:00 2026-06-08T20:04:11+00:00

i have text input to enter time and some times I need to change

  • 0

i have text input to enter time and some times I need to change time from 12 hr format to 24 format when I double click on input.. so how can me convert time like this:

1:00 => 13:00

01:00 => 13:00

(hint) my code:

   $("input").live('dblclick', function(){
    var type12 = $(this).val();
    if (type12.length == 4){
    var time = type12.replace(/\:/, '');
    var hh = time.substr(0,1);
    var mm = time.substr(0,3); // TO DO
    var type24 = Number(hh) + 12;
    var time24 = hh + mm;
    $(this).val(time24);
    sortTimes($(this).closest("tr"));
    }else{alert('not');}
});
  • 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-08T20:04:14+00:00Added an answer on June 8, 2026 at 8:04 pm

    As per my comment, here is what I would do. First of all you should really define a consistent string for your 12 hour time. I would use the format hh:mm am / hh:mm pm.

    Secondly, I would ditch the .live() for two reason, firstly, because as of jQuery 1.7 it has been depreciated and replaced by .on(), and secondly because your going to need to have functionality to convert the 24 hour time back to a 12 hour time when the button is double clicked a second time. If you were using single clicks we could use a .toggle(), however for double clicks we will need to use a plugin, and I would recommend using the jQuery-Function-Toggle-Plugin. Once included in your code it can be used like so:

    $('input').funcToggle('dblclick', function() {
        //Odd Click
    }, function() {
        // Even Click
    });
    

    Next, instead of using substrings, which while perfectly fine, we could just use .indexOf(":"), to check if the string has a : in it, and then .split(“:”) to split the string into an array. This is how I did it:

    var type12 = "12:45";
    if (type12.indexOf(":") != -1) {
        time_array = type12.split(":");
        hh = time_array[0];  //12
        mm = time_array[1];  //45
    }
    

    Full code and example can be found here –> http://jsfiddle.net/374xN/4/

    This is probably overkill for what you asked, but hopefully it will point you in the right direction.

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

Sidebar

Related Questions

I have input text: <div><label wicket:for=name>Name</label><input type=text wicket:id=name /></div> Now I need to add
Hi Guys i need some help with Jquery Validadion Plugin I have an input
I have text input boxes. There is validation for each of the boxes using
I have text input element and an event is fired on blur event and
I just wanted to ask. I have text input to allow users to type
I'm working with jquery. And i have text input in a form, i would
I have a text input : <input type=text onkeydown=processText(this) /> I have a processing
I have a text input field like text box or text area. I want
Hi I have several text input boxes, and i have a clear button, they
Im doing something quite specific where I have a text input, I 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.