我正在使用带有日期和时间选项的IntlDateTimeFormat
.然而,我很难在最后得到我想要的格式.
下面是我目前拥有的代码.我想要的结果是返回一个格式如下的字符串:
Sept 27, 2022 at 12:20 PM
个
到目前为止,当前代码返回:
27 Sept 2022 at 12:20
个
注意遗漏的AM/PM
个字母(大写字母也不错)
public dateOptions = {
month: 'short',
year: 'numeric',
day: '2-digit',
} as const;
public timeOptions = {
hour: 'numeric',
minute: 'numeric',
dayPeriod: 'narrow',
} as const;
private newDateString() {
const now = new Date();
const tz = Intl.DateTimeFormat().resolvedOptions().locale;
const date = Intl.DateTimeFormat(tz, this.dateOptions).format(now);
const time = Intl.DateTimeFormat(tz, this.timeOptions).format(now);
return `${date}` + ' at ' + `${time}`;
}