mirror of
https://github.com/samsonjs/strftime.git
synced 2026-04-27 14:57:37 +00:00
add %L for 3-digit milliseconds
This commit is contained in:
parent
2644ab016a
commit
c5362e748c
2 changed files with 21 additions and 5 deletions
14
lib/index.js
14
lib/index.js
|
|
@ -42,6 +42,19 @@
|
||||||
return n < 10 ? (padding + n) : n;
|
return n < 10 ? (padding + n) : n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pad3(n, padding) {
|
||||||
|
padding = padding || '0';
|
||||||
|
if (n < 10) {
|
||||||
|
return padding + padding + n;
|
||||||
|
}
|
||||||
|
else if (n < 100) {
|
||||||
|
return padding + n;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function hours12(d) {
|
function hours12(d) {
|
||||||
var hour = d.getHours();
|
var hour = d.getHours();
|
||||||
if (hour == 0) hour = 12;
|
if (hour == 0) hour = 12;
|
||||||
|
|
@ -101,6 +114,7 @@
|
||||||
case 'r': return strftime(locale.formats.r || '%I:%M:%S %p', d, locale);
|
case 'r': return strftime(locale.formats.r || '%I:%M:%S %p', d, locale);
|
||||||
case 'S': return pad(d.getSeconds());
|
case 'S': return pad(d.getSeconds());
|
||||||
case 's': return Math.floor(d.getTime() / 1000);
|
case 's': return Math.floor(d.getTime() / 1000);
|
||||||
|
case 'L': return pad3(Math.floor(d.getTime() % 1000));
|
||||||
case 'T': return strftime(locale.formats.T || '%H:%M:%S', d, locale);
|
case 'T': return strftime(locale.formats.T || '%H:%M:%S', d, locale);
|
||||||
case 't': return '\t';
|
case 't': return '\t';
|
||||||
case 'u':
|
case 'u':
|
||||||
|
|
|
||||||
|
|
@ -10,19 +10,21 @@ t = new Date 1307472705867
|
||||||
|
|
||||||
TESTS = [
|
TESTS = [
|
||||||
|
|
||||||
["%Y", "2011", "2011"]
|
["%L", "867"]
|
||||||
|
|
||||||
|
["%Y", "2011"]
|
||||||
|
|
||||||
["%m", "06"]
|
["%m", "06"]
|
||||||
["%b", "Jun", "Jun"]
|
["%b", "Jun"]
|
||||||
["%B", "June", "June"]
|
["%B", "June"]
|
||||||
|
|
||||||
["%d", null, "07"]
|
["%d", null, "07"]
|
||||||
|
|
||||||
["%H", null, "18"]
|
["%H", null, "18"]
|
||||||
|
|
||||||
["%M", "51", "51"]
|
["%M", "51"]
|
||||||
|
|
||||||
["%S", "45", "45"]
|
["%S", "45"]
|
||||||
|
|
||||||
["%s", "1307472705"]
|
["%s", "1307472705"]
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue