I've been using this answer to convert epoch time to DateTime. I have this epoch number:
epoch = 1549626705942
and do:
Time.at(epoch).to_datetime
However, I get this as the result:
#<DateTime: 51075-09-19T08:45:42+02:00 ((20376082j,24342s,0n),+7200s,2299161j)>
I'm using Ruby version 2.5.3p105 and my clock is set to the current year. This epoch value evaluates to today's date (February 2nd, 2019) yet I get a year 51075. Really not sure what's going on.
It's also weird because, when I enter my timestamp at a site like this one I get today's date but here I get the same result as my Ruby code.
Edit: I tried to remove the last 3 numbers of this date and got a correct date. So is it that there are 2 epoch "formats" so to say?
You are passing miliseconds to the Time::at()
method. You should pass seconds there. Link to docs is here.
To retrieve Epoch value(in seconds), use Time#to_i
UPD
This will work for you:
Time.at(0, your_epoch_milliseconds, :millisecond)