Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between moment js functions and javascript date functions [closed]

Actually i am thinking about to use moment.js in my new project.because my new project is a employee working sheet application.

I read the moment.js documents.

We can get the current date by using the below code in moment.js

moment().valueOf();

We can get the current date by using javascript

new Date()

The both are giving same result. with same speed (so no performance issue )

also formatting, get methods and set methods are already has javascript. then why i go to moment.js?

Please give me some explanations about the difference's. And let me know which one is best for my new project.

like image 662
Ramesh Rajendran Avatar asked Apr 13 '15 13:04

Ramesh Rajendran


People also ask

Is moment or date-fns better?

Date-fns simplifies the JavaScript data manipulations by providing a variety of functions. It provides more than 200 different time-related functions, and unlike MomentJS, it allows you to import a selected set of functions as needed.

What is better than MomentJS?

And today, the most popular alternative to Moment. js is Day. js which surpassed date-fns on GitHub by stars (46,2k Day. js stars vs 37,7k date-fns stars).

How do you compare date and moment time?

Compare two dates using Moment.js has a diff() method, which gives the difference between two dates in years, months, days, hours, minutes, seconds, milliseconds, etc. We can use the second unit in our case to find the difference between the two dates.

What is moment function in JavaScript?

MomentJS is a JavaScript library which helps is parsing, validating, manipulating and displaying date/time in JavaScript in a very easy way. This chapter will provide an overview of MomentJS and discusses its features in detail. Moment JS allows displaying of date as per localization and in human readable format.


1 Answers

Moment.js

A lightweight JavaScript date library for parsing, validating, manipulating, and formatting dates.

Reason why we use Moment.js - Many web applications today, especially social ones, deal with the concept of time. They are usually employed to sort events or posts, or to mark the moment in which something happens. You can think of your Twitter timeline or your GitHub news feed. JavaScript has a Date object that you can use to manipulate dates, but it often doesn’t have all you need in your web applications

The Moment.js library not only parses dates from strings, but it may also be used to validate, manipulate, and format dates. It supports internationalization, which is so important with dates, as well as human-friendly formatting like "Last Friday at 9:48".

These are all good things for sure, but today's order of the day is date parsing, so let's get into how that works.

Moment.js creates a wrapper for the Date object rather than extend it. To reference the wrapper object, simply call the moment() getter function. The Moment prototype is exposed through the moment.fn property, so you can add your own functions to it if you are so inclined.

Courtesy of

Managing Dates and Times Using Moment.js

A Roundup of Popular JavaScript Date Parsing Libraries: Moment.js

like image 103
Nidhish Krishnan Avatar answered Sep 30 '22 17:09

Nidhish Krishnan