Home > OS >  How to send javascript date object with POST request in REST CLIENT (vs code extension)?
How to send javascript date object with POST request in REST CLIENT (vs code extension)?

Time:01-20

I want to make a post request using REST CLIENT extension in VS Code.

Here's the screenshot

How can I send javascript new Date() object or moment() or dayjs() objects with the request?

I tried changing Content-type: application/javascript but it didn't work. Please suggest some solution. Thank you.

CodePudding user response:

JSON is a plain text data-interchange format and it has no built-in date/time type.

You need to format the date as a string. ISO8601 is usually used:

new Date().toISOString();
moment().toISOString();
dayjs().toISOString();

It should look like: 2023-01-20T12:17:00Z.

Then the endpoint should parse it.

  • Related