Number.prototype.padLeft = function(base,chr){
var len = (String(base || 10).length - String(this).length)+1;
return len > 0? new Array(len).join(chr || '0')+this : this;
}
$('#showit').click(function(){
var d = new Date,
dformat = [ (d.getMonth()+1).padLeft(),
d.getDate().padLeft(),
d.getFullYear()].join('-')+
' ' +
[ d.getHours().padLeft(),
d.getMinutes().padLeft(),
d.getSeconds().padLeft()].join(':');
$('#result').html(dformat);
});
See this Example Done on JS Fiddle
http://jsfiddle.net/mthdA/404/[
^]
Plz mark as answered if you got a help
If you want AM/PM Use this additional function.
http://jsfiddle.net/mthdA/406/[
^]