Time Conversion

How do I convert an integer to a time and date? Specifically, given:

t = File.mtime(x).to_i

I want to be able to:

printf("%s\n", t.to_time)

How do you define the method to_time? Doesn’t seem to be any built-ins, even though I find that odd. Nothing in class Integer, Float, or Fixnum - and nothing in ParseDate about “seconds since epoch” or integers and such.

David Douthitt
CUNA & Affiliates
UNIX Systems Administrator
ddouthitt@cuna.coop
(608) 231-4922

Look at Time.at(). In your case, I think this should work …

printf “%s\n”, Time.at(t)

···

On Tue, 23 Jul 2002 07:52, David Douthitt wrote:

How do I convert an integer to a time and date? Specifically, given:

t = File.mtime(x).to_i

I want to be able to:

printf("%s\n", t.to_time)

Hi –

···

On Tue, 23 Jul 2002, Harry Ohlsen wrote:

On Tue, 23 Jul 2002 07:52, David Douthitt wrote:

How do I convert an integer to a time and date? Specifically, given:

t = File.mtime(x).to_i

I want to be able to:

printf("%s\n", t.to_time)

Look at Time.at(). In your case, I think this should work …

printf “%s\n”, Time.at(t)

Digressing slightly from the question, but I’d put in a plug for:

puts Time.at(t)

:slight_smile:

David


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav