New Date from Time.now().to_a


#1

I don’t see any obvious ways of making a new Date object based off of
what Time.now rerurns. I’m ultimately trying to make a new Date from
milliseconds:

tn = Time.now
ms = ("%.6f" % tn.to_f) #this would ultimately be comming from another
source
nd = Time.at( ms.to_f / 1000.0 )
puts nd.to_a.inspect
#d = Date.new(??)

The next step is making the date object. I don’t see anything obvious in
the Date class. Any help?


#2

On Mar 11, 2007, at 6:02 PM, Aaron S. wrote:

I don’t see any obvious ways of making a new Date object based off of
what Time.now rerurns. I’m ultimately trying to make a new Date from
milliseconds:

tn = Time.now
ms = ("%.6f" % tn.to_f) #this would ultimately be comming from another
source
nd = Time.at( ms.to_f / 1000.0 )
puts nd.to_a.inspect

Remember, ri is your friend™.

% ri Date::civil
------------------------------------------------------------ Date::civil
Date::civil(y=-4712, m=1, d=1, sg=ITALY)


#3

Ryan D. wrote:

On Mar 11, 2007, at 6:02 PM, Aaron S. wrote:

I don’t see any obvious ways of making a new Date object based off of
what Time.now rerurns. I’m ultimately trying to make a new Date from
milliseconds:

tn = Time.now
ms = ("%.6f" % tn.to_f) #this would ultimately be comming from another
source
nd = Time.at( ms.to_f / 1000.0 )
puts nd.to_a.inspect

Remember, ri is your friend�.

% ri Date::civil
------------------------------------------------------------ Date::civil
Date::civil(y=-4712, m=1, d=1, sg=ITALY)

require ‘date’

ms = 1173658884500.0
nd = Time.at( ms.to_f / 1000.0 )
#puts nd
#puts nd.to_a.inspect
f = nd.to_a
n = Date.parse("#{f[4]}-#{f[3]}-#{f[5]} #{f[1]}:#{f[2]}:#{f[3]}
#{f[9]}")
#puts n
#puts n.class


#4

ms = 1173658884500.0
nd = Time.at( ms.to_f / 1000.0 )
#puts nd
#puts nd.to_a.inspect
f = nd.to_a
n = Date.parse("#{f[4]}-#{f[3]}-#{f[5]} #{f[1]}:#{f[2]}:#{f[3]}
#{f[9]}")
#puts n
#puts n.class

correction: Date.parse("#{f[3]}-#{f[4]}-#{f[5]} #{f[1]}:#{f[2]}:#{f[3]}
#{f[9]}")


#5

On 12.03.2007 02:27, Aaron S. wrote:

correction: Date.parse("#{f[3]}-#{f[4]}-#{f[5]} #{f[1]}:#{f[2]}:#{f[3]}
#{f[9]}")

Why the parsing?

irb(main):042:0> t=Time.now
=> Mon Mar 12 19:59:33 +0100 2007
irb(main):043:0> d=Date.new(t.year, t.month, t.day)
=> #<Date: 4908343/2,0,2299161>
irb(main):044:0> d.strftime
=> “2007-03-12”

Kind regards

robert


#6

Robert K. wrote:

On 12.03.2007 02:27, Aaron S. wrote:

correction: Date.parse("#{f[3]}-#{f[4]}-#{f[5]} #{f[1]}:#{f[2]}:#{f[3]}
#{f[9]}")

Why the parsing?

robert

thanks. thats exactly what I was looking for.