What is the best way to get the day of the year for any specific date in Ruby?
For example: 31/dec/2009
should return day 365
, and 01/feb/2008
should return day 32
Modified Julian Day Number¶ ↑ Its days begin at midnight on local time. In this document, when the term “modified Julian day number” simply appears, it just refers to “chronological modified Julian day number”, not the original. In those classes, those are so-called “amjd” and “mjd”.
A Date object is created with Date::new , Date::jd , Date::ordinal , Date::commercial , Date::parse , Date::strptime , Date::today , Time#to_date , etc. require 'date' Date. new(2001,2,3) #=> #<Date: 2001-02-03 ...> Date.
Ruby | DateTime parse() function DateTime#parse() : parse() is a DateTime class method which parses the given representation of date and time, and creates a DateTime object. Return: given representation of date and time, and creates a DateTime object.
Basically (shown here in irb):
>> require 'date' >> Date.today.to_s => "2009-11-19" >> Date.today.yday() => 323
For any date:
>> Date.new(y=2009,m=12,d=31).yday => 365
Or:
>> Date.new(2012,12,31).yday => 366
@see also: Ruby Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With