How can I convert a JavaScript date to the EDM Date format for OData usage?
let currentDate = new Date();
// Is there a native function to achieve this conversion?
The existing answers appear to be outdated, so I'm curious if the latest ECMAScript 2020 has a built-in method for this conversion.
Resources:
Important Note: This task is being performed within the Angular 10 framework.
However, when attempting to use the below function in Angular, an error was encountered:
function convertJSONDate(jsonDate, returnFormat) {
var myDate = new Date(jsonDate.match(/\d+/)[0] * 1);
myDate.add(4).hours(); //using {date.format.js} to add time and compensate for timezone offset
return myDate.format(returnFormat); //using {date.format.js} plugin to format :: EDM FORMAT='yyyy-MM-ddTHH:mm:ss'
}
Error: Property 'add' does not exist on type 'Date'; Property 'format' does not exist on type 'Date'