jdewit / bootstrap-timepicker

[Deprecated] A simple timepicker component for Twitter Bootstrap
MIT License
1.64k stars 1.09k forks source link

Leading zero in time value #323

Closed alisabzevari closed 8 years ago

alisabzevari commented 8 years ago

Is there any way to add leading zero to time? For example: 1:30 => 01:30

mrhota commented 8 years ago

Not currently, but I would love to support it. Dupe of #203

Truly, this would be supported implicitly if we internationalize the timepicker. I'm short on time.

juande32 commented 5 years ago

You can solve this by editing the following functions in the original code:

`decrementHour: function() {

  /* Added this line at the end*/
  if (this.hour < 10) {this.hour = "0" + this.hour;}

},

incrementHour: function() {

  /* Added this line at the end */
  if (this.hour < 10) {this.hour = "0" + this.hour;}
},`

setTime: function(time, ignoreWidget) {

 /* Added this line at the end */
  if (hour < 10) {hour = "0" + hour;}

  this.hour = hour;
  this.minute = minute;
  this.second = second;
  this.meridian = meridian;

  this.update(ignoreWidget);
},`
MuhammadAlfadinSalim commented 4 years ago

just an addition for juande32 answers change part in incrementHour: function() { from:

if (this.hour === this.maxHours - 1) {
        this.hour = 0;                  

        return;
      } 

to:

if (this.hour === this.maxHours - 1) {
        this.hour = "0"+0;                  

        return;
      }