I am using Rhoconnect for synchronizing Rails and Rhodes app. The db structure includes a datetime field along with others. when i display these records on rhodes app, the date time field (created_at) is showing '1330520025' instead of date and time. How can i convert this to show actual date and time.
Asked
Active
Viewed 199 times
1 Answers
0
You could use the Ruby Time.strptime funcion, that is used to parse a time string. You must pass the format as the second argument. In this case the format is '%s':
s_time = '1330520025'
require 'time'
t = Time.strptime s_time, '%s'
You can format it using this function:
t.strftime('%d/%m/%Y %I:%M:%S %p')
More details on format masks you could see in this site: http://snippets.dzone.com/posts/show/2255

Douglas Lise
- 1,466
- 1
- 20
- 46
-
Thanks. But, i want the formatting to be 3/2/2012 1:02:15 PM. How can i apply this format? – Priya Saini Mar 07 '12 at 15:27