We will answer this question by a simple example.
e.g. January 09, 2016: 2016-1-9
To handle this, you need to add leading zero to day and month if needed.
The following code will do it automatically for you.
var today = new Date(); var date = today.getFullYear() + '-' + ('0' + (today.getMonth()+1)).slice(-2) + '-' + ('0' + today.getDate()).slice(-2);
Final result: 2016-01-09