formatDate angular 显示不正确的分钟

formatDate angular showing incorrect minutes

我正在从服务器获取 GMT+0 时间并使用

将其转换为客户端时间
new Date(response[x].timeIn)

这给了我正确的时间,例如 2020 年 12 月 10 日星期四,19:15:00 GMT+0500(巴基斯坦标准时间)

但我只想从中检索我使用

的时间 (07:15 PM)
formatDate(new Date(response[x].timeIn), "hh:MM a", 'en-US')

但是 returns 07:12 PM.

每次无论是 10:00、14:45 还是其他,分钟部分都是 returns xx:12 分钟。

如果我做错了什么,谁能告诉我?

您的问题是您在 formatDate 中设置的日期格式不正确。

您使用的是 MM,即月,而不是 mm,即分钟。这就是为什么你总是得到 12,因为你的日期总是 12 月。

试试下面的代码:

formatDate(new Date(response[x].timeIn), "hh:mm a", 'en-US')