S
S
Semmy_992018-08-07 09:27:23
React
Semmy_99, 2018-08-07 09:27:23

How to format date using moment?

It is React that interests me and the main difficulty lies in the fact that there is a result of two dates:
experience is an object that stores dates

{moment(experience.end_date).diff(experience.start_date, 'days')}

The difficulty is that you need to eventually format it all in:
Year month day
or
Month day
or
days
Depending on the number of days. At the moment, I know that you can output data in the format of either only the year, or only the months, or only the days.
Is there a method that does this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2018-08-07
@jack_azizov

At the moment, I know that you can output data in the format of either only the year, or only the months, or only the days.
You can output in any format that moment.js understands. Everything your heart desires is there: https://momentjs.com/docs/#/displaying/format/.
Depending on the number of days.
https://momentjs.com/docs/#/displaying/difference/
Is there a method that does this?
No, but there are conditional statements in javascript. You need one like this:if () {}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question