2 回答
TA贡献2019条经验 获得超9个赞
使用 Intl 对象的日期格式输出在不同的实现中不一定一致。对我来说,OP 代码在不同的浏览器中会产生不同的结果:
野生动物园:2020 年 4 月 6 日 / Shaban 13, 1441
火狐:2020 年 4 月 6 日 / 13 沙班 1441 AH
铬:2020 年 4 月 6 日 / 13 沙班 1441 AH
它们在格式或字符上都不完全相同。
如果您想确保组件按您想要的顺序排列,请使用formatToParts,收集零件然后按您想要的顺序输出它们。只要确保结果是明确的(例如,使用您所做的月份名称)。
let partsHeg = new Intl.DateTimeFormat('ar-FR-u-ca-islamic', {
day: 'numeric',
month: 'long',
year: 'numeric'
}).formatToParts(Date.now());
partsHeg.forEach(part => {
if (part.type != 'literal') {
console.log(part.type + ': ' + part.value);
}
});
let partsGre = new Intl.DateTimeFormat('ar-US', {
day: 'numeric',
month: 'long',
year: 'numeric'
}).formatToParts(Date.now());
partsGre.forEach(part => {
if (part.type != 'literal') {
console.log(part.type + ': ' + part.value);
}
});
TA贡献1856条经验 获得超17个赞
您可以通过添加 RTL Unicode 的一 (1) 个语句/代码来修复此问题,以修复方向。当阿拉伯文本中的最后一个或第一个字母是拉丁字符时,就会发生这种情况。
let RTL = "\u200F"; // Added ****
var tDate = RTL + new Intl.DateTimeFormat("ar-US", { // Added RTL before
day: 'numeric',
month: 'long',
year: 'numeric'
}).format(Date.now()) +
'\xa0\xa0/ \xa0' +
new Intl.DateTimeFormat("ar-FR-u-ca-islamic", {
day: 'numeric',
month: 'long',
year: 'numeric'
}).format(Date.now());
console.log(tDate); // You can add RTL here instead console.log(RTL+tDate);
添加回答
举报
