Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i change date format to display month and year only using moment js

I would like to change this date time format using momentjs

2017-02-01T00:00:00.000Z

to

02-2017 ( month-year )

How to change this date format to get month-year only using momentjs?

I have tried like this:

var MnthYr = moment(2017-02-01T00:00:00.000Z).format("MM-YYYY");

but I didn't get exact answer

like image 949
Yuva Mac Avatar asked May 16 '17 07:05

Yuva Mac


People also ask

What is MomentJS default format?

js default date format to dd/mm/yyyy.


1 Answers

You can simply use format

Here a working sample:

console.log( moment('2017-02-01T00:00:00.000Z').format('MM-YYYY') );
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
like image 80
VincenzoC Avatar answered Sep 29 '22 06:09

VincenzoC