1

I am building a web project with mainly Vue.js and am having problems with date time formatting. When getting data from my database (which is in datetime format), I get something like '2021-01-08T00:00:00'. Now is there a way to make Day.js accept such an input and convert that to either 'dd-mm-yyyy' or 'mm-dd-yyyy' or whatever format I want? I have tried:

this.data.DateOfBirth = dayjs(e.dateOfBirth).format("dd-mm-yyyy");

But it doesn't seem to work and throws an error warning like this on the browser console:

The specified value "Su-01-yyyy" does not conform to the required format, "yyyy-MM-dd".

Many thanks!

1 Answer 1

1

format of the date is not correct.

  • dd -> day
  • mm -> minutes
  • DD -> Date
  • MM -> Month
  • YYYY -> Year

There are other formats as well. Please check the required format on the docs and use as per the requirement.

https://day.js.org/docs/en/display/format

Sign up to request clarification or add additional context in comments.

1 Comment

Sincere thanks, I solved it. At first I thought either lowercase or uppercase is ok.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.