A1X A1X - 7 months ago 16
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


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

You can try this

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

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