Thursday, August 19, 2010

Convert human readable time format to Unix Epoch format and Convert Unix Epoch time format to human readable format in ruby

In one of projects i was doing ,I was required to convert human readable datetime format to UNIX epoch format and than back to human readable format from Unix epoch
format
SO here is the code for that

Human readable time format to Unix Epoch format
up_date = DateTime.strptime("December 01, 2009", "%b %d, %Y")
up_date = up_date.to_i

and thats it
Unix Epoch time format to human readable format
Time.at(up_date).strftime "%B %d %Y"

and now you have human readable datetime format

No comments:

Post a Comment