Convert Julian Date to Calendar days
190 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I would appreciate if anyone can help me converting Julian date (508440) to calendar days (01/01/2008).
0 comentarios
Respuestas (3)
Walter Roberson
el 19 de Sept. de 2017
>> datetime(508440,'convertfrom','juliandate')
ans =
datetime
17-Dec--3321 12:00:00
>> juliandate('2008-1-1')
ans =
2454466.5
1 comentario
Peter Perkins
el 21 de Sept. de 2017
Editada: Peter Perkins
el 21 de Sept. de 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
el 14 de Feb. de 2011
2 comentarios
James Tursa
el 21 de Feb. de 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
el 21 de Feb. de 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
el 7 de Feb. de 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 comentarios
Ver también
Categorías
Más información sobre Calendar en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!