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"); 

jsfiddle


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -