MBehtemam MBehtemam - 3 months ago 36
Javascript Question

Convert Persian date to Julian or Gregorian with keith wood calendars

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

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

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

var e = d.toJD();

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


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)

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');