How to change date format in jquery using moment JS ?

Admin   JAVASCRIPT   381  2021-06-13 17:56:00

sometime, we may need to change date format mm/dd/yyyy, mm-dd-yyyy, DD-MM-YYYY, yyyy-mm-dd etc in jquery then you can do it using moment jquery library. here i will give you very simple example that way you can understand how it works, actually it's very easy to use and fantastic.

moment.js is a jquery plugin that provide to change date formate from string date. they also provide to compare date, difference between two dates etc. there are several things work with dates, it's like carbon. So i think if you are using jquery then must be use moment js plugin for change date format.

I posted in past there are several post regarding dates as listed here : How to change date format using date filter in AngularJS ?, How to change bootstrap datepicker with speific date formate example, Laravel 5 change date format using carbon example and also there are several posts available related to dates. you can find it by search.

Moment js through we can simply convert string date to specific date format. So you can use following syntax for change date format.


$(document).ready(function() {



Now we will see following simple example, in this example i give you three dates and then convert it into "DD-MM-YYYY" this format, So you can see bellow list how i give you.

1. July 1, 1994 : 01-07-1994

2. 1994-07-01 : 01-07-1994

3. 1994-07-01 : 01-07-1994

I give basic string of date, you can pass your data string and check it so let's see bellow full example, how it works.



I hope it can help you....