使用 Intl.DateTimeFormat 将公历日期转换为回历日期存在一天差异

问题描述 投票:0回答:1

我正在尝试使用 Intl.DateTimeFormat 将公历日期转换为回历日期,但每次它都会提前一天转换。例如今天是 11 斋月,但每次结果都是 12 斋月。

我已经尝试了所有日历类型“伊斯兰,伊斯兰-umalqura,伊斯兰-民事,伊斯兰-rgsa”我也尝试更改区域设置“PK,IN,AF,SA”但没有区别。这是一个错误还是我做错了什么。

console.log(new Intl.DateTimeFormat('en-PK-u-ca-islamic', {day: 'numeric', month: 'long',weekday: 'long',year : 'numeric'}).format(Date.now()))
javascript date calendar hijri
1个回答
0
投票

试试这个

const currentDate = new Date();
currentDate.setTime(currentDate.getTime() + (currentDate.getTimezoneOffset() * 60 * 1000) + (5.5 * 60 * 60 * 1000));
const islamicDate = new Intl.DateTimeFormat('en-PK-u-ca-islamic', {
  day: 'numeric',
  month: 'long',
  weekday: 'long',
  year: 'numeric'
}).format(currentDate);

console.log(islamicDate);

© www.soinside.com 2019 - 2024. All rights reserved.