Skip to content
the poor coder

moment.js format

Poor Man
Published
Reading time
1 min read

Moment.js is a JavaScript library that helps you parse, validate, manipulate, and display dates and times in JavaScript. It's a library that makes it easy to work with dates and times in JavaScript. Moment.js makes it easy to format dates and times using the familiar strftime syntax. For example, to display a date like October 2nd, 2020, you would do the following:

Text

var date = moment("2020-10-02");
console.log(date.format("MMMM Do, YYYY")); // October 2nd, 2020

You can also use Moment.js to create a formatted date from a string. For example, if you have a string like "03/01/2020", you can use Moment.js to parse it into a Date object.

Text

var dateStr = "03/01/2020";
var date = moment(dateStr, "MM/DD/YYYY");
var date_formatted = date.format("MMMM Do, YYYY"); // March 1st, 2020

Moment.js also makes it easy to add and subtract dates. For example, to add a month to a date, you would do the following:

Text

var date = moment("2020-10-02");
var date_plus_month = date.add(1, 'months');
console.log(date_plus_month.format("MMMM Do, YYYY")); // November 2nd, 2020

Moment.js is a powerful and versatile library that makes it easy to work with dates and times in JavaScript. If you're working with dates and times, it's definitely worth checking out.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC