Re: How to convert long/milliseconds to DateTime?

From: Mike Nospam

I tried this already:

t = Time.at(1161275493444)
puts t

Resulting in:
Exception: bignum too big to convert into `long’

irb(main):001:0> Time.at( 1161275493444 / 1000 )
=> Thu Oct 19 10:31:33 -0600 2006

Time#at takes its argument as the number of seconds since the epoch, not
milliseconds.

You were close! :slight_smile:

Muchas gracias. I’ll RTFM closer…

irb(main):001:0> Time.at( 1161275493444 / 1000 )
=> Thu Oct 19 10:31:33 -0600 2006

Time#at takes its argument as the number of seconds since the epoch, not
milliseconds.

You were close! :slight_smile:

Mike Nospam wrote in post #157814:

Muchas gracias. I’ll RTFM closer…

irb(main):001:0> Time.at( 1161275493444 / 1000 )
=> Thu Oct 19 10:31:33 -0600 2006

Time#at takes its argument as the number of seconds since the epoch, not
milliseconds.

You were close! :slight_smile:

Then, how to convert datetime to milliseconds in rails?

On 04/25/2012 09:54 AM, Kuberan Gopal wrote:

Then, how to convert datetime to milliseconds in rails?

time = DateTime.now
=> Wed, 25 Apr 2012 10:23:55 +0200

time.strftime(“%L”).to_i
=> 329

time.strftime(“%3N”).to_i
=> 329