Created
July 12, 2014 00:21
-
-
Save koloda/9d46e28f1d6a4b3230ae to your computer and use it in GitHub Desktop.
js - date to format function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(!Date.prototype.toLocaleFormat){ | |
Date.prototype.toLocaleFormat = function(format) { | |
var f = { | |
Y : this.getFullYear(), | |
y : this.getFullYear()-(this.getFullYear()>=2e3?2e3:1900), | |
m : this.getMonth() + 1, | |
d : this.getDate(), | |
H : this.getHours(), | |
M : this.getMinutes(), | |
S : this.getSeconds() | |
}, k; | |
for(k in f) | |
format = format.replace('%' + k, f[k] < 10 ? "0" + f[k] : f[k]); | |
return format; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment