Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
yyyy-mm-dd hh:ii:ss formatter
get_time = function() {
var date_part, local_time, now, time_part;
local_time = new Date();
now = new Date(local_time.getTime() + (local_time.getTimezoneOffset() * 60000));
date_part = "" + (this.zero_pad(now.getFullYear(), 2)) + "-" + (this.zero_pad(now.getMonth() + 1, 2)) + "-" + (this.zero_pad(now.getDate(), 2));
time_part = "" + (this.zero_pad(now.getHours(), 2)) + ":" + (this.zero_pad(now.getMinutes(), 2)) + ":" + (this.zero_pad(now.getSeconds(), 2));
return "" + date_part + " " + time_part;
}
zero_pad = function(number, length) {
var str;
str = "" + number;
while (str.length < length) {
str = "0" + str;
}
return str;
}
alert(get_time())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment