# Time.now

What units does it output - with .to_f or .to_i?

Doesn’t seem to be milliseconds. I could be wrong. Ruby-doc dogged me.
Google said Jack Ruby was writing letters to his brother Earl and
suggested japanese.

I yam confused. Whats a good reference for this?

Thanks
Csmr

On 10/25/07, Casimir [email protected] wrote:

What units does it output - with .to_f or .to_i?

Doesn’t seem to be milliseconds. I could be wrong. Ruby-doc dogged me.
Google said Jack Ruby was writing letters to his brother Earl and
suggested japanese.

I yam confused. Whats a good reference for this?

Dunno, but ri on my machine says:

for to_f:
Returns the value of time as a floating point number of seconds
since epoch.

for to_i:
Returns the value of time as a floating point number of seconds
since epoch.

Let them talk of their oriental summer climes of everlasting
conservatories; give me the privilege of making my own summer with my
own coals.

http://gnufied.org

On 10/25/07, hemant [email protected] wrote:

for to_f:
Returns the value of time as a floating point number of seconds
since epoch.

for to_i:
Returns the value of time as a floating point number of seconds
since epoch.

Oops my bad, I pasted the same thing twice. Sincere apologies,
although i hope you get the point nonetheless.

Let them talk of their oriental summer climes of everlasting
conservatories; give me the privilege of making my own summer with my
own coals.

http://gnufied.org

Let them talk of their oriental summer climes of everlasting
conservatories; give me the privilege of making my own summer with my
own coals.

http://gnufied.org

On Thu, 2007-10-25 at 20:00 +0900, Casimir wrote:

What units does it output - with .to_f or .to_i?

That’s seconds since the UNIX Epoch – 1st of January, 1970.

irb(main):003:0> now = Time.now.to_i
=> 1193313074
irb(main):004:0> #wait a few seconds
irb(main):005:0> later = Time.now.to_i
=> 1193313084
irb(main):006:0> later - now
=> 10
irb(main):007:0>

Of course, it’s totally unnecessary to cast, since the same thing
happens when you do it directly:

irb(main):008:0> now = Time.now
=> Thu Oct 25 21:51:48 +1000 2007
irb(main):009:0> later = Time.now
=> Thu Oct 25 21:51:52 +1000 2007
irb(main):010:0> later - now
=> 3.621771
irb(main):011:0>

And defaults to better precision! (unless you pick .to_f, the only
difference I mean. But it’s semantically better this way.)

Arlen