need to convert UTC time to current timezone of device

692 views Asked by At

Im using this repo

https://github.com/remirobert/Tempo

Can someone help me understand how to grab the current time zone of the device, and then notify tempo? I am using the timeAgoNow() function of tempo to find display how long ago the post was made, but the timezone difference is messing it up. My datasource is using UTC time.

1

There are 1 answers

0
Duncan C On

Cocoa uses UTC internally. for all of its date/time calculations.

If you create an NSDate for now:

NSDate()

You get a date that is the number of elapsed seconds since midnight, 1970 in UTC time.

Dates only have time zones when you display them.

By default logging a date to the console logs it in UTC, which can be confusing.

If I'm working on a project that does a lot of date/time calculations I'll create a debugging method that converts an NSDate to a date/time string in the current locale, which is easier to read/debug without having to mentally convert from UTC back to local time.

I have never used Tempo, so I don't know if it is using date strings, NSDate, or "internet dates" (which are also in UTC, but use a different "zero date" or "epoch date")