Convert Julian Date to Calendar days
조회 수: 190 (최근 30일)
이전 댓글 표시
I would appreciate if anyone can help me converting Julian date (508440) to calendar days (01/01/2008).
댓글 수: 0
답변 (3개)
Walter Roberson
2017년 9월 19일
>> datetime(508440,'convertfrom','juliandate')
ans =
datetime
17-Dec--3321 12:00:00
>> juliandate('2008-1-1')
ans =
2454466.5
댓글 수: 1
Peter Perkins
2017년 9월 21일
편집: Peter Perkins
2017년 9월 21일
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
2011년 2월 14일
댓글 수: 2
James Tursa
2011년 2월 21일
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
2011년 2월 21일
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
2019년 2월 7일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Calendar에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!