datetime - How can I convert a decimal year value into a Date in Ruby? -


input:

2015.0596924

desired output:

january 22, 2015

you can obtain formatted date follows:

require 'date'  d = 2015.0596924 year = date.new(d)   #=> #<date: 2015-01-01 ((2457024j,0s,0n),+0s,2299161j)>  date = (year + (year.leap? ? 366 : 365) * (d % 1))   #=> #<date: 2015-01-22 ((2457045j,68059s,526396957n),+0s,2299161j)>  date.strftime("%b %d, %y")    #=> "january 22, 2015" 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -