Convert Julian Date to Calendar days

98 visualizzazioni (ultimi 30 giorni)
Avelino  Langa
Avelino Langa il 14 Feb 2011
Risposto: Peter Perkins il 7 Feb 2019
I would appreciate if anyone can help me converting Julian date (508440) to calendar days (01/01/2008).

Risposte (3)

Walter Roberson
Walter Roberson il 19 Set 2017
>> datetime(508440,'convertfrom','juliandate')
ans =
datetime
17-Dec--3321 12:00:00
>> juliandate('2008-1-1')
ans =
2454466.5
  1 Commento
Peter Perkins
Peter Perkins il 21 Set 2017
Modificato: Peter Perkins il 21 Set 2017
Yes, whatever 508440 is, it is not the julian date of 1-Jan-2008. 508440 days before that date is
>> datetime(2008,1,1) - caldays(508440)
ans =
datetime
10-Dec-0615

Accedi per commentare.


Aurelien Queffurust
Aurelien Queffurust il 14 Feb 2011
You can use the formula described here: What calendar system does MATLAB use?
  2 Commenti
James Tursa
James Tursa il 21 Feb 2011
The formula listed on the link is generally incorrect for most users since it makes no adjustments for the user's time zone offset from UTC. e.g., to calculate the current Julian Date you can use this formula:
JD = datenum(now) + 1721058.5 + java.util.Date().getTimezoneOffset()/(60*24)
Or, instead of now you can use a variable of your own local time based datenum, datevec, or datestr entries.
This method assumes that your computer (via the java.util.Date() method) knows the time zone adjustment.
James Tursa
James Tursa il 21 Feb 2011
Although the above will work, I meant to type the following to be consistent with the example in the link:
JD = datenum(clock) + 1721058.5 + java.util.Date().getTimezoneOffset()/(60*24)

Accedi per commentare.


Peter Perkins
Peter Perkins il 7 Feb 2019
Michael, I can't speak for the correctness of that code, but you or that code may be confusing some things.
There's the proleptic Gregorian calendar, and there's the proleptic Julian calendar. They differ by about a month when you go back to near the Julian epoch.
Then there's the way ISO years are counted, and the way Gregorian/Julian years are counted. The former have a zero, and go negative. The latter don't have a zero, and don't go negative, but rather annotate with BC or whatever.
In any case, unless you are using MATLAB pre-R2-14b, just use datetime:
>> datetime(0,'convertfrom','juliandate')
ans =
datetime
24-Nov--4713 12:00:00
>> datetime(0,'convertfrom','juliandate','Format','dd-MMM-yyyy G HH:mm:ss')
ans =
datetime
24-Nov-4714 BCE 12:00:00
Those are in the proleptic Gregorian calendar with ISO and Gregorian year conventions, respectively.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by