I searched but found only plugins for time with "select" and the times in the AM / PM formed.
I would like one to be able to type and stay in this format:
23:59:59
I searched but found only plugins for time with "select" and the times in the AM / PM formed.
I would like one to be able to type and stay in this format:
23:59:59
This is more or less simple to do, ie a mask to insert :
when you are inserting numbers.
It may be more complex to allow too many large numbers and to exclude letters.
A simple example would be:
document.getElementById('hora').addEventListener('keyup', function(e){
var str = this.value.split(':').join('');
if (str.length > 6) str = str.slice(0, 6);
var formatado = str.match(/.{1,2}/g).join(':');
this.value = formatado;
});
These 4 lines of code explained:
:
from any string :
between them See if this helps:
var time = new Date(params.tweetDate),
h = time.getHours(), // 0-24 format
m = time.getMinutes();
Font: link
I used the jQuery-Mask-Plugin plugin: link
And I did the 24 hour time validations that I needed. It does not allow 24:59:59, 23:69:59 or 23:59:69, for example.
<script type="text/javascript" src="~/Scripts/jQueryMask/jquery.mask.js">
</script>
<script type="text/javascript">
$(document).ready(function () {
var options = {
onKeyPress: function (a, b, c) {
if (a.length == 2) {
if (parseInt(a[1]) > 3 && parseInt(a[0]) == 2) {
a = a[0];
$(c).val(a);
}
}
},
translation: {
A: { pattern: /[0-2]/ },
C: { pattern: /[0-5]/ },
B: { pattern: /[0-9]/ }
}
};
$('.time').mask('AB:CB:CB', options);
})
</script>