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

如何实现英文数字与阿拉伯语月份混合的日期格式输出?

解决方案

你要实现「年份 + 阿拉伯语月份」的显示格式,只需调整两处配置即可:

  • 修正日期模式串:你当前使用的d MMM yyyy是「日 月份 年」的顺序,替换为yyyy MMM即可匹配年在前、月份在后的需求
  • 确保传入的locale参数为阿拉伯语区域,否则会输出对应区域语言的月份名称

修正后的SimpleDateFormat示例代码

// 可根据需求指定具体阿拉伯国家区域,比如ar-SA(沙特)、ar-EG(埃及)等
Locale arabicLocale = Locale.forLanguageTag("ar");
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy MMM", arabicLocale);
dateString = dateFormatter.format(date);

补充说明

  • 如果需要显示完整的月份名称而非缩写,把模式串中的MMM替换为MMMM即可
  • Java 8及以上版本更推荐使用线程安全的java.time API实现,示例如下:
Locale arabicLocale = Locale.forLanguageTag("ar");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MMM", arabicLocale);
// 替换为你自己的日期对象即可
String dateString = LocalDate.now().format(formatter);

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 00:45:10