Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6154527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:16:40+00:00 2026-05-23T20:16:40+00:00

In Ruby I am trying to convert a Date into a format that is

  • 0

In Ruby I am trying to convert a Date into a format that is usable by the HighCharts JavaScript charting library. Odd thing is when I convert the Date to seconds it converts differently than when I convert a Time to seconds and differently when I convert a DateTime to seconds. Due to this difference in conversion the dates displayed on the Graph can be as much as 1 date behind.

I am sure this has something to do with Rails and how it handles conversion from UTC to Local. If someone could explain to me the details I would greatly appreciate it.

In my examples below I use the same date ‘2011/05/02’ but the seconds come out to be different.

Examples:

Date.new(2011, 5, 2).to_time.to_i * 1000
=> 1304265600000
=> 05/01/2011

Time.utc(2011, 5, 2).to_i * 1000
=> 1304294400000
=> 05/02/2011

Date.new(2011, 5, 2).to_datetime.to_i * 1000
=> 1304294400000
=> 05/02/2011
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:16:41+00:00Added an answer on May 23, 2026 at 8:16 pm
    ruby-1.9.2-p180 :106 > Time.utc(2011, 5, 2)
    => 2011-05-02 00:00:00 UTC 
    ruby-1.9.2-p180 :107 > Date.new(2011, 5, 2).to_time
    => 2011-05-02 00:00:00 +0300
    

    Date.to_time generates Time with timezone. That’s your difference.
    The quick fix/hack that popped instantly into my mind is:

    Date.new(2011, 5, 2).to_time.utc.midnight
    

    Edit:
    http://apidock.com/rails/Date/to_time

    Date.new(2011, 5, 2).to_time(:utc)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With ruby I'm trying to get format a date as such: 2009-10-01 Where I
I'm trying to convert an all-uppercase string in Ruby into a lower case one,
I'm trying to convert an XML document into a dataset that I can import
I'm trying to convert someone's Ruby code into my Python code. The originally developer
Trying to understand Ruby a bit better, I ran into this code surfing the
How to convert a ruby hash object to JSON? So I am trying this
I am trying to convert a document with content like the following into another
I'm trying to convert avi file to flv format using FFMPEG on server, but
I'm trying to replicate the Convert.ToBase64String() behavior in Ruby. Here is my C# code:
I am using Ruby on Rails 3 and I am trying to convert the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.