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

  • Home
  • SEARCH
  • 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 330693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:42:18+00:00 2026-05-12T09:42:18+00:00

How can I force the Time.rfc2822 function to spit out +0000 ? Ruby lets

  • 0

How can I force the Time.rfc2822 function to spit out +0000?

Ruby lets me parse RFC2822 formatted times pretty easily:

require 'time'
time = Time.parse('14 Aug 2009 09:28:32 +0000')
puts time
=> "2009-08-14 05:28:32 -0400"

But what about displaying times? Notice that the time it parsed is a local time. No worries, I can convert it back to a UTC time with gmtime:

puts time.gmtime
=> "2009-08-14 09:28:32 UTC"

I can then put it back into RFC2822 format:

puts time.gmtime.rfc2822
=> "Fri, 14 Aug 2009 09:28:32 -0000"

Unfortunately, this is not quite what I want. Notice that the +0000 is now -0000. According to RFC2822, this is because:

The form “+0000” SHOULD be used to indicate a time zone at
Universal Time. Though “-0000” also indicates Universal Time, it is
used to indicate that the time was generated on a system that may be
in a local time zone other than Universal Time and therefore
indicates that the date-time contains no information about the local
time zone.

Great – so how can I force +0000 other than monkey-patching the rfc2822 function?

  • 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-12T09:42:18+00:00Added an answer on May 12, 2026 at 9:42 am

    Here’s my monkeypatch solution:

    class Time
      alias_method :old_rfc2822, :rfc2822
      def rfc2822
        t = old_rfc2822
        t.gsub!("-0000", "+0000") if utc?
        t
      end
    end
    

    If you have a non-monkeypatch solution, I would love to see it!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 214k
  • Answers 214k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer if the query don't result any row, you can set… May 12, 2026 at 10:51 pm
  • Editorial Team
    Editorial Team added an answer If memory serves, GetModuleHandle(NULL); returns the instance handle. May 12, 2026 at 10:51 pm
  • Editorial Team
    Editorial Team added an answer Here's the most compact way I found to make this… May 12, 2026 at 10:51 pm

Related Questions

I have a CGI script that generates a file on the server and then
I have to build a DropDownList with the dates of the last 7 days.
BACKGROUND: In running my app through a profiler, it looks like the hotspots are
Let's say I have a class Customer, which has a property customerType. I have

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.