从军事时间格式化时刻到 am/pm

Formatting moment from military time to am/pm

我在格式化某些瞬间时遇到了一些困难。我从数据库中取回一串 1-24(军事时间),我正在尝试使用 moment 来格式化这个(凌晨 1 点到 12 点),将其从军事时间更改为更清晰的时间。

我已经用这个玩了一段时间了,但我现在似乎只能得到当前时间,无法弄清楚如何传递字符串。

我试过了

moment().format("hA");

还有

moment('15').format("hA");

moment(15).format("hA");

和其他一些变体。一些帮助将不胜感激。

您可以使用:

moment("16", "hh").format('hA')