2

I have a Rails 3.2.16 app where I'd like to display the current time such as Time.zone.now.strftime("%H:%M:%S") in the application.html.erb layout file in my menu header. I'd like it to display and refresh refresh every second so it keeps proper time (or as close to realtime as possible minus app latency).

What would be the best way to include this in my application.html.erb in the navbar and get it to display the time and refresh every second?

Maybe there's a Javascript or jQuery function I can use to do this or maybe some Ajax? I can get the time to display fine, but I need to figure out how to refresh it without a page reload.

Any help would be appreciated.

nulltek
  • 3,247
  • 9
  • 44
  • 94
  • You should probably see this question: http://stackoverflow.com/questions/18229022/how-to-show-current-time-in-javascript-in-the-format-hhmmss and use JavaScript for such feature – Tom Hert Oct 14 '14 at 21:59
  • @TomHert Thank you, this totally works. :) – nulltek Oct 14 '14 at 22:04
  • 1
    Possible duplicate of [How to show current time in JavaScript in the format HH:MM:SS?](https://stackoverflow.com/questions/18229022/how-to-show-current-time-in-javascript-in-the-format-hhmmss) – Kick Buttowski Feb 24 '18 at 23:10

0 Answers0