Convert Julian Date to Calendar days

60 ビュー (過去 30 日間)
Avelino  Langa
Avelino Langa 2011 年 2 月 14 日
回答済み: Peter Perkins 2019 年 2 月 7 日
I would appreciate if anyone can help me converting Julian date (508440) to calendar days (01/01/2008).

回答 (3 件)

Walter Roberson
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
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
Aurelien Queffurust 2011 年 2 月 14 日
You can use the formula described here: What calendar system does MATLAB use?
  2 件のコメント
James Tursa
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
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
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.

カテゴリ

Help Center および File ExchangeCalendar についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by