4

I need to get the current date and time javascript in the following format

YYYY-MM-DD HH:MM:SS

But cannot work out how to do it.

var d = new Date();
timesheetGrid.cellById(rId,15).setValue(d);

This is where I am using the data.

Any help would be greatly appreciated.

Lewis M Hackfath
  • 131
  • 4
  • 17

1 Answers1

5

How about simply:

d.toISOString().replace('T', ' ').replace(/\..*$/, '');

Take the ISO string, replace the "T" with a space, and trim off the milliseconds.

VoteyDisciple
  • 35,315
  • 5
  • 85
  • 89