mysql - Get current date and time in javascript of format: 2015-03-01 03:09:03 -


i want current date , time in javascript this: 2015-03-01 03:09:03

how can achieve such format? (show 0 before number when less 9)

actually comparing date , time mysql date , time in node.js mysql plugin. javascript date , time format must same mysql default date , time format i.e : 2015-03-01 03:09:03

currently using:

 var currentdate     = new date();   var datetime        = currentdate.getfullyear() + "-" +                        (currentdate.getmonth()+1)  + "-"+                        currentdate.getdate() + " "  +                         currentdate.gethours() + ":"   +                        currentdate.getminutes() + ":" +                         currentdate.getseconds(); 

mysql query in node.js:

var paramupdate = {} stateobject.connection.query("update timersdb set notificationflag = '1'                                requesttime < '"+datetime+"' ,                               notificationflag = '0'",                                paramupdate , function(err, rows){                                             if(err){                                                 throw err;                                             }                                              else{ }                                          }); 

but code generating date , time this: 2015-3-1 3:9:3 not valid according mysql date , time standards.

can guide me best possible solution achieve current date , time in javascript this: 2015-03-01 03:09:03

you need create function add leading 0 if value less 10. try this:

var currentdate     = new date();  var datetime        = addzero(currentdate.getfullyear()) + "-" +                       addzero(currentdate.getmonth()+1)  + "-"+                       addzero(currentdate.getdate()) + " "  +                        addzero(currentdate.gethours()) + ":"   +                       addzero(currentdate.getminutes()) + ":" +                        addzero(currentdate.getseconds());  function addzero(str) {     return str < 10 ? ('0' + str) : str; } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -