Skip to main content
replaced http://stackapps.com/ with https://stackapps.com/
Source Link

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?".

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?".

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?".

added 111 characters in body
Source Link
Brock Adams
  • 13k
  • 5
  • 39
  • 64

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 thosethese values even forif the API parameter is called a "Date" fields.


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?".

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 and the API takes those values even for "Date" fields.


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?".

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?".

Source Link
Brock Adams
  • 13k
  • 5
  • 39
  • 64

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 and the API takes those values even for "Date" fields.


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?".