Since the .getTime()
value is already in UTC, you can just divide by 1000, and round.
That is:
var apiDate = Math.round (new Date().getTime() / 1000);
works just fine.
apiDate
is in "unix epoch time" and the API takes these values even if the API parameter is called a "Date".
But, if you want to truncate to the date only, just use:
var dateTime = new Date ();
dateTime.setUTCHours (0);
dateTime.setUTCMinutes (0);
dateTime.setUTCSeconds (0);
var apiDate = Math.round (dateTime.getTime() / 1000);
See, also "How do I parse the dates from the API?How do I parse the dates from the API?".