0

I want to use HighCharts to render some historical data. The issue is the chart is working with dates which are parsed using Data.parse function. As explained here:

The Date.parse() method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC.

For example:

Date.parse("01/01/2013 08:00")
1357020000000

As I do not want to do JavaScript manipulation over the returned JSON I want to do the conversion in ruby. Is there such ruby function?

gotqn
  • 42,737
  • 46
  • 157
  • 243

2 Answers2

1
require 'date'
DateTime.parse("01/01/2013 08:00").strftime('%Q')
#=> "1357027200000"

Is this what you want?

For more Information see http://www.ruby-doc.org/stdlib-2.1.2/libdoc/date/rdoc/DateTime.html

mhutter
  • 2,800
  • 22
  • 30
0

I have managed to do this in the postresql like this search for EPOCH :

SELECT EXTRACT(EPOCH FROM my_date) as my_date

It gives me:

1410705430.59685

Then in the partial I just called to_i

gotqn
  • 42,737
  • 46
  • 157
  • 243