A1X A1X - 2 years ago 77
Ruby Question

Convert Active Support timezone original format into a string

I'm trying to convert Active Support timezone original format into a string. I want to store it in an array of characters then parse each needed data individually.

Time.zone = current_user.timezone
date_and_time = Time.zone.now


date_and_time = Thu, 21 Apr 2016 20:58:04 PDT -07:00

Ruby method ( to_s ) does not convert it. I found other ways to convert it to but all of them will change the format to numbers only, I want the day to stay the same because I will store it in a variable then use it in a different method.

Answer Source

You can try this

date_and_time.strftime("%a %d %b %Y")

Also You can check this guide, to get format you want

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download