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);
添加回答
舉報