Skip to content

Instantly share code, notes, and snippets.

@koloda
Created July 12, 2014 00:21
Show Gist options
  • Save koloda/9d46e28f1d6a4b3230ae to your computer and use it in GitHub Desktop.
Save koloda/9d46e28f1d6a4b3230ae to your computer and use it in GitHub Desktop.
js - date to format function
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