title: rails - convert DateTime to UTC before saving to server
body: <p>I don't know how, but my console and my server have two different timezones for DateTime.now.  If I run DateTime.now in my console, the following is returned:</p>
  
  <pre><code>Wed, 04 Dec 2013 14:27:23 -0500 
  </code></pre>
  
  <p>However, I have the following in my Task model:</p>
  
  <pre><code>def self.already_expired
      where("time_frame &lt; ?", DateTime.now)
  end
  </code></pre>
  
  <p>The goal of the code above is to fire off some task methods on tasks where 'time_Frame' is a past date.  Here is where i call the method:</p>
  
  <pre><code>task :change_it =&gt; :environment do
    puts "yo yo you yo you"
    @tasks = Task.already_expired
    @tasks.each do |task|
          puts "Kalabar" + task.inspect + "now time is:" + DateTime.now.to_s
    end
  end
  </code></pre>
  
  <p>The server logs show this:</p>
  
  <pre><code>Task Load (1.2ms)  SELECT "tasks".* FROM "tasks" WHERE (time_frame &lt; '2013-12-04 17:25:37')
      Kalabar#&lt;Task id: 3, title: "task 1 - past", content: "Should show this one", 
          created_at: "2013-12-04 17:05:53", updated_at: "2013-12-04 17:05:53", 
          schedule_id: 2, amount: nil, time_frame: "2013-12-02 08:15:00"&gt;
          now time is:2013-12-04T12:25:37-05:00
      Kalabar#&lt;Task id: 5, title: "another task - past", 
          content: "should show this one", created_at: "2013-12-04 17:11:23", 
          updated_at: "2013-12-04 17:11:23", schedule_id: 3, amount: nil, 
          time_frame: "2013-12-03 02:07:00"&gt;now time is:2013-12-04T12:25:37-05:00
      Kalabar#&lt;Task id: 6, title: "another task - future", 
          content: "should not show at first", created_at: "2013-12-04 17:11:23",
          updated_at: "2013-12-04 17:25:09", schedule_id: 3, amount: nil, 
          time_frame: "2013-12-04 12:27:00"&gt;now time is:2013-12-04T12:25:37-05:00
  </code></pre>
  
  <p>So, it is comparing time_frame to '2013-12-04 12:25:37 which is UTC.  However, when i have it print DateTime.now.to_s, it prints '2012-12-04 08:15:00'.  </p>
  
  <p>I want to convert everything to UTC before it goes into the database.  I also don't understand why it has two different timezones for DateTime.now  Here are my questions</p>
  
  <ol>
  <li>Why are there two different timezones for DateTime.now</li>
  <li>How do I convert timezones to UTC before they save to the database?  </li>
  </ol>
  
  <p>UPDATE:</p>
  
  <p>I put the following in my application.rb file:</p>
  
  <pre><code>config.time_zone = 'Eastern Time (US &amp; Canada)'
  </code></pre>
  
  <p>And now the user enters in a datetime in Eastern Time, and it gets stored as a UTC time.  So now time_frame is being compared to DateTime.now correctly.  The issue is that if i puts time_frame, it puts it in Eastern time.  I'm not really sure whats going on.  Its storing it in UTC but printing it in Eastern time.  Is this dangerous / correct?  I added a 'puts time_Frame' to the task block of code like this:</p>
  
  <pre><code>task :change_it =&gt; :environment do
    @tasks = Task.already_expired
    @tasks.each do |task|
          puts "Kalabar" + task.inspect + "now time is:" + DateTime.now.to_s
        puts "time_frame is:" + task.time_frame.to_s
    end
  end
  </code></pre>
  
  <p>and it outputs this:</p>
  
  <pre><code>Kalabar#&lt;Task id: 3, title: "task 1 - past", content: "Should show this one", created_at: "2013-12-04 17:05:53", updated_at: "2013-12-04 17:05:53", schedule_id: 2, amount: nil, time_frame: "2013-12-02 08:15:00"&gt;now time is:2013-12-04T15:27:22-05:00
  time_frame is:2013-12-02 03:15:00 -0500
  Kalabar#&lt;Task id: 7, title: "Task 1 - past by days", content: "Should always show", created_at: "2013-12-04 20:20:40", updated_at: "2013-12-04 20:20:40", schedule_id: 4, amount: nil, time_frame: "2013-12-02 09:02:00"&gt;now time is:2013-12-04T15:27:22-05:00
  time_frame is:2013-12-02 04:02:00 -0500
  Kalabar#&lt;Task id: 8, title: "Task 2 - past by minutes", content: "should always show", created_at: "2013-12-04 20:20:40", updated_at: "2013-12-04 20:20:40", schedule_id: 4, amount: nil, time_frame: "2013-12-04 20:15:00"&gt;now time is:2013-12-04T15:27:22-05:00
  time_frame is:2013-12-04 15:15:00 -0500
  </code></pre>
  
  <p>So, as you can see, in the database it is UTC, but when it puts it it is in Eastern.  Why is it doing this / is it dangerous?</p>