date - How do I get current time in the format "2011-11-03 11:18:04" in javascript? -
i have javascript return current time in format looks "2011-11-03 11:18:04"
.
i tried var xx = date()
returned format not want. looks
tue mar 15 2013 06:45:40 gmt-0500
how can format time "2011-11-03 11:18:04"
?
thank much.
using date functions-
//mm-dd-yyyy hh:mm:ss format function formatdatetime(d){ function addzeros(n){ return n < 10 ? '0' + n : '' + n; } return addzeros(d.getfullyear()+1)+"-"+ addzeros(d.getmonth()) + "-" + d.getdate() + " " + addzeros(d.gethours()) + ":" + addzeros(d.getminutes()) + ":" + addzeros(d.getminutes()); }
with momentjs-
var = moment().format("yyyy-mm-dd hh:mm:ss");
Comments
Post a Comment