[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Time.now

Casimir

10/25/2007 10:57:00 AM

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. :D

I yam confused. Whats a good reference for this?

Thanks
Csmr
3 Answers

hemant

10/25/2007 11:13:00 AM

0

On 10/25/07, Casimir <pikEISPAMMMseli@welho.com> 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. :D
>
> 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.

Hope, that answers your question.


--
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://g...

hemant

10/25/2007 11:14:00 AM

0

On 10/25/07, hemant <gethemant@gmail.com> wrote:
> On 10/25/07, Casimir <pikEISPAMMMseli@welho.com> 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. :D
> >
> > 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.
>
> Hope, that answers your question.
>
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://g...
>


--
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://g...

Arlen Cuss

10/25/2007 11:45:00 AM

0


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