如何使用ruby时间类来获取EST

时间:2021-08-27 16:30:44

I have a rails application and i need to get the Eastern standard Time using the Time class

我有一个rails应用程序,我需要使用Time类获得东部标准时间

I am just trying to make sure that we always use eastern stand time so I can sync with a countdown every 3 seconds...

我只是想确保我们总是使用东部时间,所以我可以每隔3秒钟同步倒计时......

here is the code

这是代码

Jquery code

$j(document).ready(function() {
  refresh();
  function refresh() {
    $j.getJSON("/timer", function(data) {
      console.log(data);
    });
    setTimeout(refresh, 3000);
  }
});

RAILS Controller action

RAILS控制器动作

def refresh_timer
  respond_to do |format|
    format.json { render :json => Time.now}
  end
end

1 个解决方案

#1


3  

Time.now.in_time_zone 'Eastern Time (US & Canada)'

Time.now.in_time_zone'东部时间(美国和加拿大)'

Or just use this if your server is configured to use EST:

或者,如果您的服务器配置为使用EST,请使用此选项:

Time.now.localtime

#1


3  

Time.now.in_time_zone 'Eastern Time (US & Canada)'

Time.now.in_time_zone'东部时间(美国和加拿大)'

Or just use this if your server is configured to use EST:

或者,如果您的服务器配置为使用EST,请使用此选项:

Time.now.localtime