0

When used with .format('ll') I get a year, suffix, how can I fix the above to remove it?

E.g.: Jan 29, 2018 -> Jan 29

I try to use regular to replace, but it is quite complicated.

moment().format('ll').replace(new RegExp('[^\.]?' + moment().format('YYYY') + '.?'), '')

Jan 29, 2018 -> Jan 29,

reference: https://github.com/moment/moment/issues/3341

2 Answers2

0
moment().format('ll')                                                
.replace(moment().format('YYYY'), '') // remove year
.replace(/\s\s+/g, ' ')// remove double spaces, if any
.trim() // remove spaces from the start and the end
.replace(/[рг]\./, '') // remove year letter from RU/UK locales
.replace(/de$/, '') // remove year prefix from PT
.replace(/b\.$/, '') // remove year prefix from SE
.trim() // remove spaces from the start and the end
.replace(/,$/g, '')

Thanks: Localizing day and month in moment.js

0

How about using Javascript split :

console.log(moment().format('ll').split(',')[0]);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>
Jordy
  • 1,802
  • 2
  • 6
  • 25