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

132
Views
How do I produce same time format using Javascript as my Ruby on Rails format does?

How do I format .created_at to produce the same time format as my Ruby code?

Javascript / jQuery

<script>
  setInterval(function () {
    fetch('/pages/markets.json')
    .then((response) => response.json())
    // .then((data) => console.log(data))
    .then((data) => { 
      $('#container').html('')
      data.forEach((item) => { 
        $('#container').append('<li><div id="created" class="text-xs mb-1">' + item.created_at + '</div><div id="text" >' +  item.tweet_text +'</div></li>')
      })
    });
  }, 10000); 
</script>

Returns: 2022-08-15T13:55:32.089Z

Ruby on Rails

t.created_at.in_time_zone("Eastern Time (US & Canada)").strftime('%I:%M %p')

Returns: 01:30 PM

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I think it's better to send formatted date to frontend from backend

But if you can't, you can use moment.js

moment(item.created_at).tz('America/New_York').format('hh:mm A')

or

moment.tz(item.created_at, 'EST').format('hh:mm A')

Please look:

https://momentjs.com

https://momentjs.com/timezone

You can also use vanilla JS Intl.DateTimeFormat

Intl.DateTimeFormat('en', { hour: '2-digit', minute: '2-digit', timeZone: 'EST' }).format(new Date(item.created_at))
about 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!