Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
Round millseconds timestamp to nearest 30 seconds

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
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Using the time you provided, I think this will do what you want:

  1. Take your time, convert it to an integer
  2. divide by floating point value 30 the number of half minutes
  3. round that value and multiple by 30 to get back to the number of seconds
  4. Create a new time object based on the rounded value.
input = Time.at(1648059542,287000)
Time.at((input.to_i / 30.0).round * 30)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!