将波斯日期转换为朱利安或格列高利与基思木日历

问题描述:

我用波斯语即时 Keith Wood日历库创建了一个日期对象:

I created a date object with Keith Wood calendar library with Persian instant:

var d = $.calendars.newDate(1393, 5, 6, 'persian', 'fa'); 

现在我需要从这个日期获取朱利安或格里高利日期,但是当我使用 .toJD()函数返回不等于

Now I need to get Julian or Gregorian date from this date but when I use .toJD() function it returns Julian date that does not equal to current date in

 var e = d.toJD();
 console.log(e) 

所以如何解决这个问题?我为此问题创建了一个 jsbin

so how do i fix this problem? I've created a jsbin for this problem .

我认为 toJD()不是你需要的: / p>

I think toJD() is not what you need:

var d = $.calendars.newDate(1388, 1, 1, 'persian', 'fa');
console.log("Persian date: "+d.toLocaleString()); // Persian date: 1388-01-01
var e = d.toJSDate();
console.log(e); // Sat Mar 21 2009 00:00:00 GMT+0100 (Romance Standard Time)

更新:对于您的评论,我看到问题没有解决,因为它将波斯日期转换为您的地区日期。就我在图书馆的参考中可以看到,没有办法告诉那个函数应该使用locale。所以正确的方式,正如作者提供的示范展示,正在创建另一个目标日历并传递当前一个作为参数:

UPDATE: For your comment I see the issue is not solved with this because it transforms the Persian date to your locale date. As far as I can see in the library's reference, there is no way to tell that function wich locale should be used. So the correct way, as the author's provided demo shows, is creating another target calendar and pass the current one as parameter:

var d = $.calendars.newDate(1388, 1, 1, 'persian', 'fa');
var e = $.calendars.newDate(d, 'gregorian', 'fa');