You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular DatePipe格式化问题:如何输出指定日期时间格式

Fixing Angular DatePipe Format When Adding "at" Text

Got it, I know exactly what's going on here! The issue is that Angular's DatePipe treats certain letters in the format string as special placeholders—like a which stands for AM/PM. When you wrote 'dd MMM, y. at h:mm a', the a in "at" got interpreted as that AM/PM placeholder instead of plain text, which caused the weird output you saw.

Here are two solid solutions to get the exact format you want (19 Jan 2023. at 14:15):

1. Wrap Plain Text in Single Quotes

You can tell DatePipe to treat specific parts as literal text by wrapping them in single quotes. Just adjust your format string like this:

{{order.updatedAt | date: 'dd MMM, y. \'at\' HH:mm'}}

(Note: I switched to HH:mm here since your example uses 24-hour time; if you still want 12-hour with AM/PM, keep h:mm a instead.)

If you prefer using double quotes for the format string, you can use unescaped single quotes inside:

{{order.updatedAt | date: "dd MMM, y. 'at' HH:mm"}}

This will output the "at" as plain text without messing up the date formatting.

2. Split the Date and Text Separately

Another straightforward approach is to split the formatted date and the fixed "at" text into separate parts, then concatenate them:

{{order.updatedAt | date: 'dd MMM, y.'}} at {{order.updatedAt | date: 'HH:mm'}}

This avoids any conflicts with format placeholders entirely, since you're handling the date segments independently from the static text.

Either of these methods will give you the exact date-time format you're looking for!

内容的提问来源于stack exchange,提问作者snowgroomer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 16:30:35