This repository has been archived by the owner on Apr 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 440
/
dateformat.js
110 lines (104 loc) · 3.54 KB
/
dateformat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var _dateFormats = module.exports = {
_months: {
full: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
abbr: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
_days: {
full: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
abbr: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
alt: {'-1': 'Yesterday', 0: 'Today', 1: 'Tomorrow'}
},
// Day
d: function (input) {
return (input.getDate() < 10 ? '0' : '') + input.getDate();
},
D: function (input) {
return _dateFormats._days.abbr[input.getDay()];
},
j: function (input) {
return input.getDate();
},
l: function (input) {
return _dateFormats._days.full[input.getDay()];
},
N: function (input) {
return input.getDay();
},
S: function (input) {
return (input.getDate() % 10 === 1 && input.getDate() !== 11 ? 'st' : (input.getDate() % 10 === 2 && input.getDate() !== 12 ? 'nd' : (input.getDate() % 10 === 3 && input.getDate() !== 13 ? 'rd' : 'th')));
},
w: function (input) {
return input.getDay() - 1;
},
//z = function (input) { return ''; },
// Week
//W = function (input) { return ''; },
// Month
F: function (input) {
return _dateFormats._months.full[input.getMonth()];
},
m: function (input) {
return (input.getMonth() < 9 ? '0' : '') + (input.getMonth() + 1);
},
M: function (input) {
return _dateFormats._months.abbr[input.getMonth()];
},
n: function (input) {
return input.getMonth() + 1;
},
//t = function (input) { return ''; },
// Year
//L = function (input) { return ''; },
//o = function (input) { return ''; },
Y: function (input) {
return input.getFullYear();
},
y: function (input) {
return (input.getFullYear().toString()).substr(2);
},
// Time
a: function (input) {
return input.getHours() < 12 ? 'am' : 'pm';
},
A: function (input) {
return input.getHours() < 12 ? 'AM' : 'PM';
},
//B = function () { return ''; },
g: function (input) {
return input.getHours() === 0 ? 12 : (input.getHours() > 12 ? input.getHours() - 12 : input.getHours());
},
G: function (input) {
return input.getHours();
},
h: function (input) {
return (input.getHours() < 10 || (12 < input.getHours() < 22) ? '0' : '') + (input.getHours() < 10 ? input.getHours() : input.getHours() - 12);
},
H: function (input) {
return (input.getHours() < 10 ? '0' : '') + input.getHours();
},
i: function (input) {
return (input.getMinutes() < 10 ? '0' : '') + input.getMinutes();
},
s: function (input) {
return (input.getSeconds() < 10 ? '0' : '') + input.getSeconds();
},
//u = function () { return ''; },
// Timezone
//e = function () { return ''; },
//I = function () { return ''; },
O: function (input) {
return (input.getTimezoneOffset() < 0 ? '-' : '+') + (input.getTimezoneOffset() / 60 < 10 ? '0' : '') + (input.getTimezoneOffset() / 60) + '00';
},
//T = function () { return ''; },
Z: function (input) {
return input.getTimezoneOffset() * 60;
},
// Full Date/Time
//c = function () { return ''; },
r: function (input) {
return input.toString();
},
U: function (input) {
return input.getTime() / 1000;
}
};