Reputation: 66657
I have following ruby code to get current time in "milliseconds", for example: 1648059542287
which is equivalent to Wed Mar 23 2022 18:19:02
What I need is timestamp rounded to nearest 30 seconds, for above example, I need it rounded to 1648059540000
. Any suggestions?
@ctime = Time.now.to_f
(@ctime * 1000).to_i
Upvotes: 1
Views: 255
Reputation: 16758
Using the time you provided, I think this will do what you want:
input = Time.at(1648059542,287000)
Time.at((input.to_i / 30.0).round * 30)
Upvotes: 2