Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert datetime to format in ruby on rails

How could I convert the following date string into accepted format in ruby on rails

Thu, Aug 25 12:00 AM

Also I want global solution that could also go with the following formats including the above given:

August 25 2016
like image 980
Syed Asad Abbas Zaidi Avatar asked Dec 05 '25 07:12

Syed Asad Abbas Zaidi


1 Answers

if variable is Time or Date class

[variable].strftime("%a, %B %d %T:%s %P")

[variable].strftime("%B %d %Y")

if you want to see more format directives

check it out http://apidock.com/ruby/DateTime/strftime

like image 190
ogelacinyc Avatar answered Dec 07 '25 20:12

ogelacinyc