How to properly extract a time only from the datetime object (post.created_at, to be precise) with/without the influence of TimeZone? How to extract the day, month, year? How to extract the day/month/year via a custom pattern (is it possible)?
+7
A:
Time in String format:
post.created_at.strftime("FORMAT STRING HERE")
# Without the influence of time-zone: I take it that you want UTC
post.created_at.utc.strftime("FORMAT STRING HERE")
Link for the strftime
documentation:
http://ruby-doc.org/core/classes/Time.html#M000298
For getting the hour, minute and second values:
post.created_at.hour
post.created_at.min
post.created_at.sec
Swanand
2009-08-11 12:37:32
Shoot, that's exactly what I needed! Thanks!
gmile
2009-08-11 13:11:14