I am encountering an issue with formatting a date string. The date is currently in the format 2021-03-31T00:00:00
, and I need it to be displayed as 31 Mar 2021
.
In my TypeScript code, I attempted to use the following function:
const formattedDate = i.SuspensionEndDate.toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric' });
However, upon running the code in the browser, I received the following error in the console:
jQuery.Deferred exception: date.toLocaleDateString is not a function TypeError: date.toLocaleDateString is not a function
A similar error occurred when trying to extract only the day element using getDate():
const formattedDate = i.SuspensionEndDate.getDate();
jQuery.Deferred exception: date.getDate is not a function TypeError: date.getDate is not a function
This error is unfamiliar to me, as I have successfully performed similar tasks with JavaScript before. However, this is my first time encountering it while working on a .ts TypeScript file.