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

如何通过date-fns在日期与时间之间添加'at'字符?

解决方案

你只需要把'at'用英文单引号包裹后插入到格式字符串里即可,date-fns会将单引号内的内容当作普通文本直接输出,不会解析为日期格式指令。

示例代码:

import { format } from 'date-fns';

const targetDate = new Date();
const formattedResult = format(targetDate, "MMM d 'at' hh:mm aa");
// 输出示例:Nov 15 at 10:00 PM

注意:一定要使用英文单引号包裹'at',如果用中文引号会被当作格式字符解析,导致输出异常。

内容的提问来源于stack exchange,提问作者marcus-linmarkson

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 16:10:26