My ts file:
mydate: Date = new Date('2021-11-14T18:30:00.000 00:00');
I want in this format:-
07-July-2022
Plzz Help
CodePudding user response:
Note: When parsing date strings with the Date constructor (and Date.parse, they are equivalent), always make sure that the input conforms to the ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ) — the parsing behavior with other formats is implementation-defined and may not work across all browsers. Support for RFC 2822 format strings is by convention only. A library can help if many different formats are to be accommodated.
Date-only strings (e.g. "1970-01-01") are treated as UTC, while date-time strings (e.g. "1970-01-01T12:00") are treated as local. You are therefore also advised to make sure the input format is consistent between the two types.
Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date
It is not recommended to parse strings like that with the Date object. You really should give a library a try. While moment.js was a popular choice in the past, I personally have a great experience with date-fns.
Docs: https://date-fns.org/
CodePudding user response:
The simplest way is using the day.js
dayjs("2022/07/07").format("DD-MMMM-YYYY")