i have successfully find the full name of month but i want short name of month. Can anyone help me. I am using Moment.js i have successfully find the month but i want in short form
here is my code :
var date = '<?php echo date("Y-m-d") ?>';
var Month = moment(date, 'YYY-MM-DD').format('DD/MMMM')
console.log(Month);
it returns me 06/February
, But i want 06/Feb
Thanks in advance :)
To get month name from two digit month number with JavaScript, we can use the moment. js' format method. We call format with 'MMMM' to get the full month name. As a result, formattedMonth is 'October' since we called month with 9 before calling format .
Try moment('2020-03-30'). add(1, 'months') and then compare with moment('2020-03-31'). add(1, 'months') .
The moment(). hour() Method is used to get the hours from the current time or to set the hours. Syntax: moment().hour(); or. moment().
You are not using correct format string, use MMM
instead of MMMM
see Docs
console.log(moment().format('DD/MMM'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
As an addendum to Satpal's answer, a simpler (kind of faster/safer approach) would be to go with the Localized formats because preferred formatting differs based on locale.
moment().format('ll') - Sep 4, 1986
Where as
moment().format('LL') - September 4, 1986
Optionally to include time:
moment().format('lll') - Sep 4, 1986 8:30 PM
Where as
moment().format('LLL') - September 4, 1986 8:30 PM
use below month formats to get required output :
console.log(`Month Number : moment().format('M') ==> `,moment().format('M'))
console.log(`Month Number : moment().format('Mo') ==> `,moment().format('Mo'))
console.log(`Month Number : moment().format('MM') ==> `,moment().format('MM'))
console.log(`3 Letter Month Name : moment().format('MMM') ==> `,moment().format('MMM'))
console.log(`Full Month Name : moment().format('MMMM') ==> `,moment().format('MMMM'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With