I am fetching data from the server and part of that data is time. Time is stored in UTC in my DB so what I'm returning is also in UTC. For example: 2014-05-22 05:12:40
Further, I am using the DateTools to show the time difference on the device like X hours ago
or X minutes ago
etc....
The problem is that when the UTC time coming from the server is compared to the local time there is a huge difference. Something that should say X seconds ago
says X hours ago
because of the time difference.
Question
How can I convert the date coming from the server to the local time zone set on the device?
This is what I'm doing right now:
@date_formatter = NSDateFormatter.alloc.init
@date_formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
@date_from_server = "2014-05-22 05:12:40"
@date = @date_formatter.dateFromString(@date_from_server)
@time.text = @date.shortTimeAgoSinceNow