Search code examples
ruby-on-railsrubydatetimepicker

rails DateTime.parse for DateTime posting from client from a jquery time picker


after upgrading to Rails 3.2 and Ruby 1.9.3 my forms which contains a jquery date picker, stopped working..

in my params is see the date:

"created_at"=>"03/22/2013 05:28 am"

but if i try to parse it like so:

DateTime.parse(params[:entry]["created_at"])

then it returns this error:

* ArgumentError Exception: invalid date

how can i parse this kind of datetime and then turn it into UTC?

thanks


Solution

  • Hope you are looking for the following.

     DateTime.strptime(params[:entry]["created_at"], '%m/%d/%Y %H:%M %P')
    

    This will output the following result

    Fri, 22 Mar 2013 05:28:00 +0000