Why you can not use toLocaleDateString() inbuilt javascript function. This function is capable to give you return as per your format. Here is my code snippet to use it.
CODE
// Parse our locale string to [date, time]
var date = new Date().toLocaleString('en-US',{hour12:false}).split(" ");
// Now we can access our time at date[1], and monthdayyear @ date[0]
var time = date[1];
var mdy = date[0];
// We then parse the mdy into parts
mdy = mdy.split('/');
var month = parseInt(mdy[0]);
var day = parseInt(mdy[1]);
var year = parseInt(mdy[2]);
// Putting it all together
var formattedDate = year + '-' + month + '-' + day + ' ' + time;
Default Date.toLocaleString() returns is a format of:
MM/DD/YYYY, HH:MM:SS
Morover, you can use Date() function to create an date object with the current date. If you want to get date in specific format you might need to refer
Date and time in JavaScript article. Here is snipprt for the date object.
CODE
var today = new Date();
var date = today.getFullYear() + '-' + (today.getMonth()+1) + '-' + today.getDate();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var date_time = date + ' ' + time;
Thank you