I use dayjs in my typescript/javascript code. I want to convert a DayJs date into the below format. How to do it?
2020-04-25T00:00:00+00:00
Here is what I tried –
dayjs().format('YYYY-MM-DD hh:mm:ss Z');
But, it gives dates which look different from my desired format. For example –
2020-04-25T00:00:00.000Z
2
Answers
To format string to show plus sign in DayJS you can use the format string YYYY-MM-DDTHH:mm:ssZ, where T is a literal string "T" that separates the date and time, and Z represents the timezone offset in the format ±hh:mm. Let me know if this code works for you.
Don’t need any 3rd party Date library. Use native Intl.DateTimeFormat.
Intl.DateTimeFormat.prototype.formatToParts()
Below is an example of how to use this method. You will need to modify it to get your desired outcome: