I changed locale to 'he' and use this format:
moment().format('D MMM')
it formated like this: 3 אפר׳ but I want to show date with this symbol 'ב' which means (3 in Apr) like this: 3 באפר׳
How can I make this? Thanks in advance
CodePudding user response:
The format string can contain other characters than just date part placeholders, you can do it directly:
moment.locale('he');
console.log(moment('2022-04-03').format('D בMMM'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.3/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.3/locale/he.js"></script>
CodePudding user response:
You can do this without moment at all. The Intl
object does this without any additional libraries in modern JS. If you want to support IE then you might need moment, if not, I'd recommend using Intl
over moment. Not least of which, because moment is deprecated.
const intl = new Intl.DateTimeFormat('he', {month: "short", day:"numeric"});
console.log(intl.format(new Date('2022-04-03')));
CodePudding user response:
I dont think that there is a built in method for that in moment.js, but you can use regex:
moment().format('D MMM').replace(/\d ? /, '$&ב')