Search code examples
rubydatetimejulian-date

Getting accurate Julian date number for current time in Ruby


Date.today.jd returns a rounded number. Is there a way to get more precision in Ruby?

I want to return a Julian date for the current time in UTC.


Solution

  • The Date#amjd method does what you're asking for, but it returns a Rational; converting to a Float gives you something easier to work with:

    require 'date'
    
    DateTime.now.amjd.to_f # => 56759.82092321331