Ruby: Converting date from one timezone to another
I always forget how to do date/time conversion in Ruby so I thought I would dump it here for future reference.
I wanted to convert from +00:00 to +10:00 but it obviously works for any offset.
# Parse
dt = DateTime.parse(issue.updated_at)
# Convert
local_dt = dt.new_offset(DateTime.now.offset)
# Display
local_dt.strftime("%I:%M %p - %d-%b-%Y")
Written by Matthew Riddle
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#