priyanka
priyanka

Reputation: 325

In ruby, how to convert epoch milli seconds into Time Object without losing milli seconds information?

I want to convert epoch milli seconds into Time without losing mill second information. Is it doable?

Upvotes: 1

Views: 631

Answers (1)

Lucas Costa
Lucas Costa

Reputation: 1129

You should use Time.at and then usec method to get the microseconds of time.

epoch_milli = 1479383961245
t = Time.at(epoch_milli / 1000.0) # => 2016-11-17 09:59:21 -0200
micro = t.usec                    # => 244999
milli = micro / 1000.0            # => 244.999

Upvotes: 2

Related Questions