Convert Julian Date to Calendar days
58 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I would appreciate if anyone can help me converting Julian date (508440) to calendar days (01/01/2008).
0 commentaires
Réponses (3)
Walter Roberson
le 19 Sep 2017
>> datetime(508440,'convertfrom','juliandate')
ans =
datetime
17-Dec--3321 12:00:00
>> juliandate('2008-1-1')
ans =
2454466.5
1 commentaire
Peter Perkins
le 21 Sep 2017
Modifié(e) : Peter Perkins
le 21 Sep 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
Aurelien Queffurust
le 14 Fév 2011
2 commentaires
James Tursa
le 21 Fév 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
le 21 Fév 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)
Peter Perkins
le 7 Fév 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.
0 commentaires
Voir également
Catégories
En savoir plus sur Calendar dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!