Search code examples
jquerytimespinner

Jquery time spinner simplify


I wanted to use time spinner from the JQueryUI example page, but I dont need culture selector, I want it work only in german style (time select: 0-24). How could I convert it simply? Sorry for my poor english, Thanks!


Solution

  • You specify your desired culture, then initialize the widget:

    <p>
      <label for="spinner">Time spinner:</label>
      <input id="spinner" name="spinner" value="20:30">
    </p>
    
    $.widget( "ui.timespinner", $.ui.spinner, {
        options: {
          // seconds
          step: 60 * 1000,
          // hours
          page: 60
        },
    
        _parse: function( value ) {
          if ( typeof value === "string" ) {
            // already a timestamp
            if ( Number( value ) == value ) {
              return Number( value );
            }
            return +Globalize.parseDate( value );
          }
          return value;
        },
    
        _format: function( value ) {
          return Globalize.format( new Date(value), "t" );
        }
    });
    
    Globalize.culture("de-DE");
    $("#spinner").timespinner();
    

    Demo