Concerting a Date Object into a UNIX Timestamp

D

Dennis Oelkers

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
 
S

Simon Strandgaard

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

Dennis Oelkers

In [email protected] Simon Strandgaard said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top