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 :)
您没有使用正确的格式字符串,请使用MMM
而不是MMMM
请参阅文档
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
使用moment(date, 'YYY-MM-DD').format('DD/MMM')
。
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.