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 6595623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:57:48+00:00 2026-05-25T17:57:48+00:00

When Rails3 serializes ActiveSupport::TimeWithZone to json that dates look something like this: 2011-07-20T23:59:00-07:00 …

  • 0

When Rails3 serializes ActiveSupport::TimeWithZone to json that dates look something like this:

“2011-07-20T23:59:00-07:00”

… it should be …

“2011-07-20T23:59:00-0700”

That last colon is problematic when trying to convert that string using standard date formatting patterns … none of them account for the use of a colon!

So my question is, “How do I override/change the serialization for TimeWithZone so that as_json returns a valid string that can be understood using the standard date format patterns?”

Right now I have to strip that last colon out in my client app but that just seems pooch.

  • 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-25T17:57:49+00:00Added an answer on May 25, 2026 at 5:57 pm

    It is a monkey patch, but hey it is Ruby and that is allowed.

    module ActiveSupport
      class TimeWithZone
        def to_json
          super.gsub(/:(?!.*:)/,'')
        end
      end
    end
    

    Tested by running:

    Time.zone = 'Eastern Time (US & Canada)'
    Time.zone.now.to_json # Outputs -> 2011-09-22T16:46:28-0400
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Rails3 how do I retrieve all records that have a date of this
This is probably one of the things that all new users find out about
I have this json object (which i don't really know what is inside) and
I have a rails3 form that allows the user to edit a list of
With Rails 3, the default session storage mechanism is cookie_store. I assume that this
I am creating a rails 3 backend that consists of RESTful json controllers. E.g.
In my Rails3 app, I am using ActiveRecord and Postgresql . Say I have
I am playing with rails3-jquery-autocomplete gem and it works me pretty well. Here is
After installing rails3, I'm experiencing problems when trying to use haml with it. I
I am using rails3 and gem devise and i have two roles admin and

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.