Skip to content

Instantly share code, notes, and snippets.

@michikono
Last active December 12, 2015 09:28
Show Gist options
  • Save michikono/4751269 to your computer and use it in GitHub Desktop.
Save michikono/4751269 to your computer and use it in GitHub Desktop.
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