If you are already using jQuery UI in your project, you can use the built-in datepicker method for formatting your date object:
$.datepicker.formatDate('yy-mm-dd', new Date(2007, 1 - 1, 26));
However, the datepicker only formats dates, and cannot format times.
Have a look at jQuery UI datepicker formatDate, the examples.