Time from now using Moment JS

Manymore developers are struggling to display time from now such as days ago, weeks ago, in N months, months/years ago, etc in JavaScript therefore today we’ll come with a new article where you will find the way to implement time from now using Moment JS.

In the previous JS article, we have explain how to Convert seconds to minutes and hours in JavaScript. In today’s article we will use Moment.js to get the time difference.

Add Moment Script

Use the below moment script to get time from now.

Display timeago

Let’s use the below method to display time that is handled by moment. Moment has two different methods .fromNow() and .fromNow(Boolean) to get output.

The .fromNow(Boolean) method will be used to get a value without a suffix. We have already shown you the sample code in above snippets.

Check out the link for more information about the time range and output.

You can refer to one more article that we wrote in JavaScript using Moment.

Convert local time to another timezone using Moment JS

That’s it for today.
Thank you for reading. Happy Coding..!!

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

2 Responses

  1. Temitayo says:

    Thanks for this piece.
    I want to ask if there is an algorithm that can help get yesterday’s date or last week date in a read-only using react, if a user enter today’s date.

Leave a Reply

Your email address will not be published. Required fields are marked *