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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:23:59+00:00 2026-06-16T02:23:59+00:00

How can a method take the current Time.zone and put it into a format

  • 0

How can a method take the current Time.zone and put it into a format that is usable by ActiveSupport::TimeZone[some_zone].parse()?

It seems very strange that Time.zone.to_s returns a string that can not be used with ActiveSupport::TimeZone[zone].parse()

Time.zone.to_s returns "(GMT-08:00) Pacific Time (US & Canada)"

But ActiveSupport::TimeZone["(GMT-08:00) Pacific Time (US & Canada)"] is nil.

ActiveSupport::TimeZone["(GMT-08:00) Pacific Time (US & Canada)"]
# => nil

ActiveSupport::TimeZone["Pacific Time (US & Canada)"]
# => (GMT-08:00) Pacific Time (US & Canada)
  • 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-06-16T02:24:00+00:00Added an answer on June 16, 2026 at 2:24 am

    Use Time.zone.name, not Time.zone.to_s

    [1] pry(main)> Time.zone.to_s
    => "(GMT-05:00) Eastern Time (US & Canada)"
    [2] pry(main)> Time.zone.name
    => "Eastern Time (US & Canada)"
    [3] pry(main)> ActiveSupport::TimeZone[Time.zone.name]
    => (GMT-05:00) Eastern Time (US & Canada)
    

    As for how I got this (as requested), I just know the name method exists on Time.zone. If I didn’t know this by heart though, I will check the docs. If it’s not in there as you say (and it is, here), I typically inspect the class/module/object with Pry. Pry is an alternative to irb that lets me do something like

    [1] pry(main)> cd Time.zone
    [2] pry(#<ActiveSupport::TimeZone>):1> ls -m
    Comparable#methods: <  <=  ==  >  >=  between?
    ActiveSupport::TimeZone#methods: <=>  =~  at  formatted_offset  local  local_to_utc  name  now  parse  period_for_local  period_for_utc  to_s  today  tzinfo  utc_offset  utc_to_local
    self.methods: __pry__
    [3] pry(#<ActiveSupport::TimeZone>):1> name
    => "Eastern Time (US & Canada)"
    

    ls -m on line [2] above prints methods on the object (if you scroll right you’ll see name listed there). You can see in [3] I can call name directly on the Time.zone object I’m inside of and get the output you’re looking for.

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

Sidebar

Related Questions

How can I specify that a method should take as parameter a pointer to
I have code in my Page_load method that can take up to a few
I'm trying to write (or just find an existing) PHP method that can take
Is it true that the WebInvoke attribute can take GET as a method? I
Can a ASP .NET Controller action method take an interface as one of the
I have a long running method which can take a minute. On my local,
I have the method Process(IEnumerable<Record> records) which can take UP TO but NO MORE
Which method can be used to read one line at a time from a
Can this method work? public String sayHello(){ return Hello.jsp?name= + laala; } I am
What tool or method can I use to see what code something like an

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.