[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Concerting a Date Object into a UNIX Timestamp

Dennis Oelkers

11/19/2003 4:15:00 PM

Hello beloved Ruby-Community,

maybe a stupid question because I probably missed something reading the
reference of "Programming Ruby", but how do I convert a Date Object into
a UNIX Timestamp (seconds passed since the UNIX epoch)?

Kind regards,
Dennis Oelkers
--
Dennis Oelkers | Webadministration | Zentraleinrichtung Rechenzentrum
TU-Berlin | EN-Gebaeude, K042 | Telefon: 030-314-25029

Key Fingerprint:
A6 7A B6 90 09 56 E8 32 02 40 6B 27 80 17 00 89 61 E7 CA 6F
2 Answers

Simon Strandgaard

11/19/2003 4:23:00 PM

0

On Wed, 19 Nov 2003 17:15:08 +0100, Dennis Oelkers wrote:
> maybe a stupid question because I probably missed something reading the
> reference of "Programming Ruby", but how do I convert a Date Object into
> a UNIX Timestamp (seconds passed since the UNIX epoch)?

irb(main):001:0> Time.now.to_i
=> 1069258948
irb(main):002:0>

--
Simon Strandgaard

Dennis Oelkers

11/19/2003 4:31:00 PM

0

In pan.2003.11.19.16.23.18.103013@sneakemail.com Simon Strandgaard <qj5nd7l02@sneakemail.com> wrote:

> On Wed, 19 Nov 2003 17:15:08 +0100, Dennis Oelkers wrote:
> > maybe a stupid question because I probably missed something reading the
> > reference of "Programming Ruby", but how do I convert a Date Object into
> > a UNIX Timestamp (seconds passed since the UNIX epoch)?
>
> irb(main):001:0> Time.now.to_i
> => 1069258948
> irb(main):002:0>

Ah, thank you very much for that helpful (and quick!) response,
in fact I tried the to_i method, but on a Date object (doh!).

irb(main):002:0> Date.new(2003, 11, 19).to_i
NoMethodError: undefined method `to_i' for #<Date: 4905925/2,0,2299161>
from (irb):2
irb(main):003:0>

Kind regards,
Dennis Oelkers
--
Dennis Oelkers | Webadministration | Zentraleinrichtung Rechenzentrum
TU-Berlin | EN-Gebaeude, K042 | Telefon: 030-314-25029

Key Fingerprint:
A6 7A B6 90 09 56 E8 32 02 40 6B 27 80 17 00 89 61 E7 CA 6F