-1

I'm having trouble to find the format for making like :

6 a.m.

I'm wondering if someone know which string i need to enter to outputFormat for make it the format as describe.

moment(openTime, inputFormat).format(outputFormat)

This format:

'a.m.'

Barak
  • 654
  • 13
  • 30
  • 1
    Does this answer your question? [How to get am pm from the date time string using moment js](https://stackoverflow.com/questions/44971954/how-to-get-am-pm-from-the-date-time-string-using-moment-js) – Dani Sep 14 '20 at 11:02
  • @Dani , No because the format there is 'AM' and i asked for 'a.m.' – Barak Sep 14 '20 at 11:04
  • Follow this link for your answare https://stackoverflow.com/questions/26043820/display-12-hour-and-24-hour-time – Md. Abu Sayed Sep 14 '20 at 11:05
  • Try this - `moment().format('DD-MM-YYYY hh:mm A').replace(/PM|AM/ig, (match) => [...match].join('.'));` – Kunal Mukherjee Sep 14 '20 at 11:08

1 Answers1

1

Moment.js doesn't have the exact format output you want, but you can produce it using two .replaces afterwards.

var m = moment();

var s = m.format('h a');
console.log(s);

s = s.replace('am', 'a.m.').replace('pm', 'p.m.');
console.log(s);

m = m.add(12, 'hours');

s = m.format('h a');
console.log(s);

s = s.replace('am', 'a.m.').replace('pm', 'p.m.');
console.log(s);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.28.0/moment.min.js"></script>
Pedro Lima
  • 1,576
  • 12
  • 21