What is the purpose of Moment.js?

Asked

Viewed 508 times

0

I bought a new bootstrap template for my system, and it came with an included business that returns several alerts, Moment.js.

From what I understand it is like a client-side validation library with language support and conversion of some date formats and I didn’t understand anything else besides that.

Example:

I have a daterange to generate reports, and when active this daterange, Moment notifies my console:

Deprecation Warning: Moment(). subtract(period, number) is deprecated. Please use Moment(). subtract(number, period).

But the code works, and if I correct that informed Warning, the daterange stops working as it should.

The question is:

What is Moment.js really for. ?

What I can do with it ?

Note: I ask this because I didn’t really see any use in it, and several templates come with it coupled, but I believe I’m wrong about that and that provavelment it should be useful.

  • 5

    Moment.js is the largest (and perhaps the best) library to work with Javascript dates. If the code stops working when you correct the code for the syntax/API that the warning indicates I suggest you put an example here in the question to help us.

  • @Sergio my doubt is not for the code or some error, I treat dates with PHP on my system, I want to understand what it is and what to do with it, and who knows how to use it, because I could not understand alone how it works.

  • 1

    The API for working with javascript date/time is kind of limited, the idea of Moment.js is to fill these gaps and make certain tasks simpler. See a example

  • @Can you give me a link with an article about him ? the ones I read didn’t clarify much, it’s just tutorial on how to do things or it’s a very simple summary, can be in English without problems

1 answer

1


This message indicates that whoever created the template used discontinued commands from moment.js:

Deprecation Warning: Moment(). subtract(period, number) is deprecated. Please use Moment(). subtract(number, period).

Moment.js is a lib used to work with date and time, their API allows you to make calculations and formatting easier.

If you are issuing these warnings then you need to ask the template developer to make the necessary adjustments, he probably wrote the first versions of the template using the code according to an older version of Moment.js, when he went to upgrade Moment.js he didn’t notice the warnings.

This message specifies that you quoted is mentioned in https://momentjs.com/docs/#/manipulating/subtract/

Before version 2.8.0, the Moment#subtract(String, Number) syntax was also supported. It has been deprecated in favor of Moment#subtract(Number, String).

Then change the codes similar to this:

 moment().subtract('seconds', 1); // Deprecated in 2.8.0

For something like this:

 moment().subtract(1, 'seconds');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.