Skip to content

Commit 2b52725

Browse files
Fix ampm bug in formatTime
1 parent 4ee9097 commit 2b52725

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

index.html

+6-4
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,10 @@ <h2>Formatting Your Time</h2>
365365
<p>The default format is "hh:mm tt", however ampm is turned off by default, so you will see "hh:mm"</p>
366366

367367
<dl class="defs">
368-
<dt>h</dt><dd>Hour with no leading 0</dd>
369-
<dt>hh</dt><dd>Hour with leading 0</dd>
368+
<dt>H</dt><dd>Hour with no leading 0 (24 hour)</dd>
369+
<dt>HH</dt><dd>Hour with leading 0 (24 hour)</dd>
370+
<dt>h</dt><dd>Hour with no leading 0 (12 hour)</dd>
371+
<dt>hh</dt><dd>Hour with leading 0 (12 hour)</dd>
370372
<dt>m</dt><dd>Minute with no leading 0</dd>
371373
<dt>mm</dt><dd>Minute with leading 0</dd>
372374
<dt>s</dt><dd>Second with no leading 0</dd>
@@ -507,8 +509,8 @@ <h3 id="basic_examples">Basic Initializations</h3>
507509
<pre>
508510
$('#basic_example_3').datetimepicker({
509511
timeFormat: "h:m t",
510-
pickerTimeFormat: "HH:mm",
511-
ampm: true
512+
pickerTimeFormat: "HH:mm"//,
513+
//ampm: true
512514
});
513515
</pre>
514516
</div>

jquery-ui-timepicker-addon.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -1150,15 +1150,11 @@
11501150
hour = 12;
11511151
}
11521152

1153-
var result;
11541153
if (hour < 10) {
1155-
result = "0" + hour;
1156-
}
1157-
else {
1158-
result = String(hour);
1154+
hour = "0" + hour;
11591155
}
11601156

1161-
return result;
1157+
return String(hour);
11621158
};
11631159

11641160
/*
@@ -1181,11 +1177,11 @@
11811177
var tmptime = format,
11821178
ampmName = options.amNames[0],
11831179
hour = parseInt(time.hour, 10);
1184-
if (options.ampm) {
1185-
if (hour > 11) {
1186-
ampmName = options.pmNames[0];
1187-
}
1180+
1181+
if (hour > 11) {
1182+
ampmName = options.pmNames[0];
11881183
}
1184+
11891185
tmptime = tmptime.replace(/(?:HH?|hh?|mm?|ss?|[tT]{1,2}|[lz]|('.*?'|".*?"))/g, function(match) {
11901186
switch (match) {
11911187
case 'HH':

0 commit comments

Comments
 (0)