113 // see http://www.quirksmode.org/js/introdate.html#year |
113 // see http://www.quirksmode.org/js/introdate.html#year |
114 var y = this.getYear() % 100; |
114 var y = this.getYear() % 100; |
115 return (y < 38) ? y + 2000 : y + 1900; |
115 return (y < 38) ? y + 2000 : y + 1900; |
116 } |
116 } |
117 |
117 |
|
118 Date.prototype.getTwelveHours = function() { |
|
119 return (this.getHours() <= 12) ? this.getHours() : 24 - this.getHours(); |
|
120 } |
|
121 |
118 Date.prototype.getTwoDigitMonth = function() { |
122 Date.prototype.getTwoDigitMonth = function() { |
119 return (this.getMonth() < 9) ? '0' + (this.getMonth()+1) : (this.getMonth()+1); |
123 return (this.getMonth() < 9) ? '0' + (this.getMonth()+1) : (this.getMonth()+1); |
120 } |
124 } |
121 |
125 |
122 Date.prototype.getTwoDigitDate = function() { |
126 Date.prototype.getTwoDigitDate = function() { |
123 return (this.getDate() < 10) ? '0' + this.getDate() : this.getDate(); |
127 return (this.getDate() < 10) ? '0' + this.getDate() : this.getDate(); |
124 } |
128 } |
125 |
129 |
|
130 Date.prototype.getTwoDigitTwelveHour = function() { |
|
131 return (this.getTwelveHours() < 10) ? '0' + this.getTwelveHours() : this.getTwelveHours(); |
|
132 } |
|
133 |
126 Date.prototype.getTwoDigitHour = function() { |
134 Date.prototype.getTwoDigitHour = function() { |
127 return (this.getHours() < 10) ? '0' + this.getHours() : this.getHours(); |
135 return (this.getHours() < 10) ? '0' + this.getHours() : this.getHours(); |
128 } |
136 } |
129 |
137 |
130 Date.prototype.getTwoDigitMinute = function() { |
138 Date.prototype.getTwoDigitMinute = function() { |
143 return this.getTwoDigitHour() + ':' + this.getTwoDigitMinute(); |
151 return this.getTwoDigitHour() + ':' + this.getTwoDigitMinute(); |
144 } |
152 } |
145 |
153 |
146 Date.prototype.getHourMinuteSecond = function() { |
154 Date.prototype.getHourMinuteSecond = function() { |
147 return this.getTwoDigitHour() + ':' + this.getTwoDigitMinute() + ':' + this.getTwoDigitSecond(); |
155 return this.getTwoDigitHour() + ':' + this.getTwoDigitMinute() + ':' + this.getTwoDigitSecond(); |
|
156 } |
|
157 |
|
158 Date.prototype.strftime = function(format) { |
|
159 var fields = { |
|
160 c: this.toString(), |
|
161 d: this.getTwoDigitDate(), |
|
162 H: this.getTwoDigitHour(), |
|
163 I: this.getTwoDigitTwelveHour(), |
|
164 m: this.getTwoDigitMonth(), |
|
165 M: this.getTwoDigitMinute(), |
|
166 p: (this.getHours() >= 12) ? 'PM' : 'AM', |
|
167 S: this.getTwoDigitSecond(), |
|
168 w: '0' + this.getDay(), |
|
169 x: this.toLocaleDateString(), |
|
170 X: this.toLocaleTimeString(), |
|
171 y: ('' + this.getFullYear()).substr(2, 4), |
|
172 Y: '' + this.getFullYear(), |
|
173 '%' : '%' |
|
174 }; |
|
175 var result = '', i = 0; |
|
176 while (i < format.length) { |
|
177 if (format.charAt(i) === '%') { |
|
178 result = result + fields[format.charAt(i + 1)]; |
|
179 ++i; |
|
180 } |
|
181 else { |
|
182 result = result + format.charAt(i); |
|
183 } |
|
184 ++i; |
|
185 } |
|
186 return result; |
148 } |
187 } |
149 |
188 |
150 // ---------------------------------------------------------------------------- |
189 // ---------------------------------------------------------------------------- |
151 // String object extensions |
190 // String object extensions |
152 // ---------------------------------------------------------------------------- |
191 // ---------------------------------------------------------------------------- |