Note that there are some explanatory texts on larger screens.

plurals
  1. POFormat time in 24 hour format in textbox blur event
    text
    copied!<p>i have created two text box which will take time as input from user i want when user press tab key the value of text box converted to 24 hour format i have written a method</p> <pre><code> function getFormattedTime(value) { var time = j$.trim(value); var len = time.length; var result = ""; var pos = time.indexOf(":"); if (pos &lt; 0) { pos = time.indexOf("."); } if (time.indexOf('m') &lt; 0 &amp;&amp; pos &lt; 0 &amp;&amp; parseInt(time) &gt; 12 &amp;&amp; parseInt(time) &lt; 12) { time = time + 'm'; } if (time.indexOf('m') &gt; 0) { time = parseFloat(time.substring(0, time.indexOf('m'))); if (isNaN(time)) { window .alert("Hours entered is invalid [00:00] or [00.00] or [00h] or [00m]"); return ""; } else { if (time &gt; 59) { result = parseInt(time / 60); result = result + ":" + (time - (result * 60)); } else { result = "00:" + (parseFloat(time) &lt;= 9 ? "0" + time : time); } } return result; } var hour = "00"; if (time.charAt(0) == '0') { hour = '0' + (parseFloat(time.substring(1, 2)) ? parseFloat(time .substring(1, 2)) : '0'); } else { hour = (parseFloat(time.substring(0, 2)) ? parseFloat(time .substring(0, 2)) : '00'); hour = (hour &gt; 24 ? 24 : (hour &lt; 10 ? (hour == 0 ? '00' : '0' + hour) : hour)); } var mins = "00"; if (pos != -1) { if (time.charAt(pos + 1) == '0') { mins = '0' + (parseFloat(time.substring(pos + 2, pos + 3)) ? parseFloat(time.substring(pos + 2, pos + 3)) : '0'); } else { mins = (parseFloat(time.substring(pos + 1, 5)) ? parseFloat(time.substring(pos + 1, 5)) : '00'); mins = (mins &gt;= 60 ? 59 : (mins &lt; 10 ? (mins &gt;= 6 ? 59 : mins + '0') : mins)); mins = (hour == 24 ? 45 : mins); } } result = hour + ":" + mins; return result; } </code></pre> <p>It is working fine for following format</p> <p>1.) 0 - 00:00 2.) 9.3 - 09:30 3.) 13.3 - 13:30 4.) 9 - 09:00</p> <p>but when i enter </p> <p>1352 it should give me 13:52 but it is giving 13:00 where i did wrong any help ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload