Search code examples
javascriptjqueryjquery-uijquery-ui-datepickertime-format

jQuery Timepicker-Addon don't show correct time format


I got stuck with jQuery Timepicker-Addon on display time format text and I need your help.

The scenario is simple. I have a list of time format; when I change time format, the datetimepicker change the format according to.

The datetimepicker work well with format from Year -> Minute. But when I set time format to hh:mm:ss, hh:mm:ss.SSS, datetimepicker only show minute unit.

I set timeFormat in beforeShow event but its seem timepicker-addon have default timeformat and I cannot override inside beforeShow.

To summarize, when I choose format

  • YYYY -> 2016 --> OK

  • YYYY/MM -> 2016/07 --> OK

  • ...

  • hh:mm -> 2016/07/23 17:05 --> OK

  • hh:mm:ss -> 2016/07/23 17:05 --x--> Expect: 2016/07/23 17:05:10

  • mm:ss.SSS -> 2016/07/23 17:05 --x--> Expect: 2016/07/23 17:05:10 123

Here is my codepen: http://codepen.io/manhle/pen/AXaWYj

Please point me out where I was missing.

Thanks in advances.

References: https://github.com/trentrichardson/jQuery-Timepicker-Addon/issues/56


Solution

  • Because timeFormat in setting doesn't effect to timepicker, just effect to datepicker.

    So, I need to change default time format of timepicker by add this line inside beforeShow event.

    instance.settings.timepicker._defaults.timeFormat = timeFormat;