Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
829 views
in Technique[技术] by (71.8m points)

javascript - 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 .toJD() function it returns Julian date that does not equal to current date in

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 to that function which 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');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...