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
and year
values? How to extract the day/month/year
via a custom pattern (is it possible)?
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#method-i-strftime
For getting the hour, minute and second values:
post.created_at.hour
post.created_at.min
post.created_at.sec
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With