# Time.now

**URL:** <https://www.ruby-forum.com/t/time-now/118296>\
**Category:** Ruby\
**Created:** [October 25, 2007, 1:00pm UTC](https://www.ruby-forum.com/t/time-now/118296 "2007-10-25T13:00:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Casimir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Casimir](https://www.ruby-forum.com/u/Casimir)\
**Post date:** [October 25, 2007, 1:00pm UTC](https://www.ruby-forum.com/t/time-now/118296/1 "2007-10-25T13:00:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Casimir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Casimir](https://www.ruby-forum.com/u/Casimir)\
**Post date:** [October 25, 2007, 1:14pm UTC](https://www.ruby-forum.com/t/time-now/118296/2 "2007-10-25T13:14:17Z")

</div>

On 10/25/07, Casimir [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

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://gnufied.org](http://gnufied.org)

---

<div class="post-metadata">

**Author:** ![Casimir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Casimir](https://www.ruby-forum.com/u/Casimir)\
**Post date:** [October 25, 2007, 1:16pm UTC](https://www.ruby-forum.com/t/time-now/118296/3 "2007-10-25T13:16:02Z")

</div>

On 10/25/07, hemant [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.
> 
> 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://gnufied.org](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](http://gnufied.org)

---

<div class="post-metadata">

**Author:** ![Casimir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Casimir](https://www.ruby-forum.com/u/Casimir)\
**Post date:** [October 25, 2007, 1:45pm UTC](https://www.ruby-forum.com/t/time-now/118296/4 "2007-10-25T13:45:52Z")

</div>

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
