Digital Clock

Hello Group.
I got my first page up and running and now I’m trying to make it look
a bit nicer.
I was thinking about putting a clock on the page, can anyone point me
to a tutorial or have a routine already done?
I’m currently using the Time.now(:short) form, but that is just
static.
Anyway any help would be greatly appreciated
Thanks
James

No Ruby required. Just use JavaScript…
http://www.javascript-page.com/clock.html

Preston

try AJAX periodically_call_remote

example

demo4.rhtml

Test periodically_call_remote

<%= periodically_call_remote(:update => 'show_date_time_id',:url => { :action => :show_date_time }, :frequency => 1 )%>

ajax_controller.rb

def show_date_time
render :text=>“Now : #{DateTime.now.to_s}”
end

try AJAX periodically_call_remote

example

demo4.rhtml

Test periodically_call_remote

<%= periodically_call_remote(:update => 'show_date_time_id',:url => { :action => :show_date_time }, :frequency => 1 )%>

ajax_controller.rb

def show_date_time
render :text=>“Now : #{DateTime.now.to_s}”
end

I thought the same thing, just imagine one lets the browsertab open for
hours without any further action.

Anyway, I need to show my users the servertime, there might be a
difference to the users machinetime, even if we are talking about a few
minutes, so the best would be to make an initial call to rubys TimeClass
for getting the servertime and from then on to display/update the time
clientside.

Even if it´s offtopic, if someone has an approach it would be very
welcome

matthi

That would be a very unwise decision, for quite a number of reasons:

  1. Your server will be bombarded with requests
  2. The clock will never show the right time, because of latency
    between the request and the response.

So, if you want to show the right time, use client-side javascript,
period.

On 22 Mar 2007, at 13:00, [email protected] wrote:

ajax_controller.rb

def show_date_time
render :text=>“Now : #{DateTime.now.to_s}”
end

Best regards

Peter De Berdt

On 23 Mar 2007, at 09:59, matthibcn wrote:

clientside.

Even if it´s offtopic, if someone has an approach it would be very
welcome

Although it wouldn’t exactly be 100% accurate, it would only differ a
few seconds from the actual server time. Calculate the offset from
the server time with the client’s time using one request, then
display the client side time plus or minus the offset.

Best regards

Peter De Berdt

If someone could give an example or link on how to calculate the offset
between clientside and serverside times that would be great.

Thank you in advance.

Peter De Berdt wrote:

On 23 Mar 2007, at 09:59, matthibcn wrote:

clientside.

Even if it´s offtopic, if someone has an approach it would be very
welcome

Although it wouldn’t exactly be 100% accurate, it would only differ a
few seconds from the actual server time. Calculate the offset from
the server time with the client’s time using one request, then
display the client side time plus or minus the offset.

Best regards

Peter De Berdt

Answering my on question but after searching google finally found a
solution.
Here is the link if anyones interested.
http://www.geocities.com/lok_2000_tom/clock.htm

Only change function sClock values in the hours, minutes and seconds to
rubys Time.now.strftime("%H") for hours and so on.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs