JQuery input mask for 12 hour time format

I use the jquery inputMask library ( https://github.com/RobinHerbots/jquery.inputmask ). But feel free to let me know if there is a better inputMask library. But I need inputMask, not a time collector.

The scenario is to have an inputMask in a time field. We want to display and have an inputMask based on a user locale so that it supports both 12-hour and 24-hour format. Initially, we only supported the 24-hour format, so the mask code looks like this:

$('input[id$="endTime"]').inputmask("hh:mm:ss", {placeholder: "HH:MM:SS", insertMode: false, showMaskOnHover: false});

Remember that we also need to maintain seconds. For the 12 hour format, I really tried several formats, but none of them worked well for me. So is it possible to disguise it?

+4
source share
1 answer
$('input[id$="endTime"]').inputmask("hh:mm:ss", {
        placeholder: "HH:MM:SS", 
        insertMode: false, 
        showMaskOnHover: false,
        hourFormat: 12
      }
   );

Demo

Tips. Open the file jquery.inputmask.bundle.js, search datetimeand see all the options for it.

(Sorry, I cannot add a comment because I do not have enough limit point to do this.)

+10
source

Source: https://habr.com/ru/post/1623180/


All Articles