〜大約正午
lw = 88.743 # my longitude
jdate = Date.ordinal_to_jd(Time.now.year, Time.now.yday)
n = (jdate - 2451545 - 0.0009 - lw/360).round # lw is users longitude west of 0.
j_noon = 2451545 + 0.0009 + lw/360 + n
puts j_noon
=> 2455616.24740833
作爲更新,混亂的部分將是正午太陽是所有 計算,因爲1月1日,4713 BC格林威治中午開始。使用Ruby Date類的天文數據
Date.ordinal_to_jd的正確使用尚未彌補這一事實。因此,通過 加上或減去12小時這樣的:
jdn = Date.ordinal_to_jd(Time.now.year, Time.now.yday) - 0.5
我們應該得到更少的錯誤。雖然我們使用了哪些,但由於我們的計算 從昨天中午開始?
該代碼是從這個頁面的兩個方程派生的Sunrise_equation。
我從這裏用戶那裏得到的第一個回答是,我們不明白使用 0.0009和LW/360 LW/360似乎是弧從 本初子午線分數的日子。至於0.0009,它必須是自公元前4713年1月1日格林尼治中午公元前 秒以內的少量變化。請參閱IAU標準更多信息
根據此page我計算它爲0.007776秒。
我有一些來自Date類的信息,不包括方法的細節。
=begin
--------------------------------------------------------------------- Class: Date
Class representing a date.
See the documentation to the file date.rb for an overview.
Internally, the date is represented as an Astronomical Julian Day Number, ajd.
The Day of Calendar Reform, sg, is also stored, for conversions to other date formats.
(There is also an of field for a time zone offset,
but this is only for the use of the DateTime subclass.)
A new Date object is created using one of the object creation class methods named
after the corresponding date format, and the arguments appropriate to that date
format; for instance, Date::civil()
(aliased to Date::new()) with year, month, and day-of-month, or Date::ordinal() with
year and day-of-year.
All of these object creation class methods also take the Day of Calendar Reform as an
optional argument.
Date objects are immutable once created.
Once a Date has been created, date values can be retrieved for the different date
formats supported using instance methods. For instance, #mon() gives the Civil month,
#cwday() gives the Commercial day of the week, and #yday() gives the Ordinal day of
the year. Date values can be retrieved in any format, regardless of what format was
used to create the Date instance.
The Date class includes the Comparable module, allowing date objects to be compared
and sorted, ranges of dates to be created, and so forth.
---------------------------------------------------------------------------------
Includes:
Comparable(<, <=, ==, >, >=, between?)
Constants:
MONTHNAMES: [nil] + %w(January February March April May June July August
September October November December)
DAYNAMES: %w(Sunday Monday Tuesday Wednesday Thursday Friday Saturday)
ABBR_MONTHNAMES: [nil] + %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
ABBR_DAYNAMES: %w(Sun Mon Tue Wed Thu Fri Sat)
ITALY: 2299161
ENGLAND: 2361222
JULIAN: Infinity.new
GREGORIAN: -Infinity.new
Class methods:
_load, _parse, _strptime, ajd_to_amjd, ajd_to_jd, amjd_to_ajd, civil, civil_to_jd,
commercial, commercial_to_jd, day_fraction_to_time, gregorian?, gregorian_leap?, jd,
jd_to_ajd, jd_to_civil, jd_to_commercial, jd_to_ld, jd_to_mjd, jd_to_ordinal,
jd_to_wday, julian?, julian_leap?, ld_to_jd, mjd_to_jd, new, now, ordinal,
ordinal_to_jd, parse, s3e, strptime, time_to_day_fraction, today, valid_civil?,
valid_commercial?, valid_jd?, valid_ordinal?, valid_time?
Instance methods:
+, -, <<, <=>, ===, >>, _dump, ajd, amjd, asctime, civil, commercial, ctime, cwday,
cweek, cwyear, day, day_fraction, downto, england, eql?, gregorian, gregorian?, hash,
hour, inspect, italy, jd, julian, julian?, ld, leap?, mday, min, mjd, mon, month,
new_offset, new_start, next, next_day, offset, ordinal, sec, sec_fraction, start,
step, strftime, succ, time, to_s, to_yaml, upto, wday, weeknum0, weeknum1, wnum0,
wnum1, yday, year, zone
=end
作爲一個方面說明,Ruby有一種方法可以計算出Julian日期。 我在尋找來自NOAA的Javascript代碼。
這是一個我受到啓發的鏈接寫的類。
class JulianDayNumber
def initialize(year = 2000, month = 1, day = 1) #defaults to Jan. 01, 2000
@year = year
@month = month
@day = day
end
def calcJDN
if (@month <= 2) then
@year -= 1
@month += 12
end
varA = (@year/100).floor
varB = 2 - varA + (varA/4).floor
jdn = (365.25*(@year + 4716)).floor \
+ (30.6001*(@month+1)).floor \
+ @day + varB - 1524.5
return jdn
end
end
jd = JulianDayNumber.new(2011, 3, 2)
julianday = jd.calcJDN
puts julianday
=> 2455622.5
現在,這讓我有,但我仍然爲研究的方式回到了許多這樣的 由最上面的公式計算出的一個。嘗試這一點,我們可以看到我們在JDN中獲得了0.5。誰是對的? Ruby還是NOAA?
NOAA使用的2451545.0在2000年1月1日值從JD減去獲取時間 分數世紀這樣
def calcTimeJulianCent(j)
t = (j - 2451545.0)/36525.0
return t
end
有關Julian Day歷史的更多信息,請參閱http://en.wikipedia.org/wiki/Julian_day#History – Douglas 2011-05-18 16:26:25