How to show nsdate without converting to local time zone? - objective-c

I want to present a date to the user in the dates own timezone. So without it being converted to the users timezone.
Basically what happens: I retrieve a string '2015-04-01T15:35:00-04:00' from the backend, and I convert it to a NSDate. Later on I want to show the user the time: 15:35.
But NSDateFormatter converts the date to my system time zone (+02:00) which results in showing 21:35.
I've searched all over the internet to find out I can skip this convert, but I can't find anything.
What do I miss?
Help is really appreciated.

You will have to save the original timezone in addition to the NSDate representation and use it when you want to present the time in the original timezone.
NSDate keeps the date/time relative to GMT (UTC).

Related

Is there a SQL function to convert to PST or PDT depending on the date?

I would like to convert times from pacific to UTC. However, I must first convert the times to either PST or PDT depending on the date. Is there a SQL function that can do this, or does anyone have any advice for creating this function?
The link you provided is pretty much useless as a guide to timestamps. If you are going to work with timezones then store your timestamps in a timestamp with time zone field. The timezone will not actually be stored but the timestamp will be stored as a UTC. Whenever a timestamp is entered it is rotated to a UTC value. This makes working with value easier down the road. If you want to take into account DST transitions you will need to use full timezone names e.g. US/Pacific, as they cover the two offsets(PST/PDT) that constitute the standard/daylight savings timezones. As you found using the offset PST(-08) or PDT(-07) gets you a fixed offset regardless of date.

RestKit Date Parsing Uses Incorrect Timezone

If part of the data that RestKit gets from my server is a timestamp formatted as 2013-05-27 20:32:26 UTC, and later I want to find out the difference between the current time and this date, I do
NSTimeInterval difference = [[NSDate date] timeIntervalSinceDate:dateFromRestKit];
But this always seems to be off for me by 1 hour, and I'm guessing this is because I'm on BST, which is UTC+1. So I think that RestKit is ignoring the timezone specified in the date string, and is instead parsing the date using the current system timezone.
I understand that there may be some technical reason it ignores the time zone, but I found all this time stuff really difficult to get my ahead around so I'm not sure.
How can I work out the correct difference between the times?
Even if your timestamp contains the UTC format , try to specify the timezone for it again.
If you want the resulting difference of two date timezone in 'UTC' then , convert the other one in UTC format and then find the time Interval.
Do let me know , if any query. Or if possible , post your code , to get more clear about your question. (:

'Normalized' NSDateFormatter

I have to parse strings like 2012-06-06T18:00:00 or 2012-06-06 without any timezone information. When I parse this the date formatter uses the local timezone and takes DST into account.
But what the date actually means is that this event occurs on 2012-06-06 not depending on the timezone, but on 2012-06-06T00:00:00 in every timezone.
Should I store the year/month/day values separately?
The same time in different time zones will correspond to different absolute times (which are represented by NSDate). So one NSDate object cannot represent what you are trying to represent. You will need one NSDate per time zone you are interested in.
You can create an NSDateComponent instance with your string. Then use NSCalender with the locale (time zone) you want to transform those date components into an NSDate (a point in time).

Get a consistent date format from NSDate?

I'm using NSDates as keys for an NSDictionary, but for key value coding, I need a string. Importantly, I need it to not change representation across OSes or locales. When I show it to users, I'll use NSDateFormatter, of course, but internally it must always be the same. What's the best way get a consistent format as a string?
Use NSDateFormatter and specify the time zone as GMT and the local as "en_US_POSIX".
From Apple's: Data Formatting Guide
If you're working with fixed-format dates, you should first set the
locale of the date formatter to something appropriate for your fixed
format. In most cases the best locale to choose is en_US_POSIX, a
locale that's specifically designed to yield US English results
regardless of both user and system preferences.
Another option is to convert a NSDate to a NSTimeInterval with a method such as timeIntervalSince1970 and then to a hexascii value to use as a key. NSDate returns a time value relative to an absolute reference dateā€”the first instant of 1 January 2001, GMT.

How can I convert Flickr's "date_create" and "date_update" into an NSDate using NSDateFormatter?

I'm using ObjectiveFlickr to retrieve a collection of photos from Flickr. The dates are returned as strings like "1309695647".
What are these numbers? Milliseconds? I can't figure out how to define a date format to convert them into NSDate objects using NSDateFormatter :(
The Flickr documentation doesn't help and I can't find anything on google :(
The high probability is that these dates are regular timestamps (unsigned int, number of seconds since January 1, 1970). See below:
http://www.flickr.com/services/api/misc.dates.html
Posted dates
The 'posted' date represents the time
at which the photo was uploaded to
Flickr. This is set at the time of
upload.
The posted date is always passed
around as a unix timestamp, which is
an unsigned integer specifying the
number of seconds since Jan 1st 1970
GMT.
All posted dates are passed around in
GMT and it's up to the application
provider to format them using the
relevant viewer's timezone.