Skip to content

Instantly share code, notes, and snippets.

@oscarmorrison
Created November 1, 2015 23:41
Show Gist options
  • Save oscarmorrison/fc10377e3824f0f6792b to your computer and use it in GitHub Desktop.
Save oscarmorrison/fc10377e3824f0f6792b to your computer and use it in GitHub Desktop.
Javascript get current date
//"YYYY-MM-DD hh:mm"
function zeroFill(i){
return (i<10 ? '0' : '') + i;
}
var getDate = function(){
var d = new Date();
var year = d.getFullYear();
var month = zeroFill(d.getMonth())
var day = zeroFill(d.getDate())
var hour = zeroFill(d.getHours())
var min = zeroFill(d.getMinutes())
return year+'-'+month+'-'+day+' '+hour+':'+min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment