0

In .plist file there's a field:

plist

I do read it in a simple dictionary. Everything's okay, but on the client side, he says the time difference is -3 hours (i.e. he sees Dec 31, 2013, 10:30 PM)

I think, I should archive the project with his region settings, right?

UPD

  • Date is stored in plist.
  • The date: 1:30 AM -> this should the client see.
  • Also, I use NSDateFormatter :

self.customFormatter = [NSDateFormatter new];

[self.customFormatter setDateFormat:@"hh:mm a"];

then I convert to string using [self.customFormatter stringFromDate:date]

And I think - I should look in .plist file and change the

<date>2014-01-01T01:30:00Z</date> 

into

<date>2014-01-01T01:30:00-3</date> // I see Dec 2013, 10:30 PM; client sees Jan 2014, 1:30 AM

right?

Aleksey Potapov
  • 3,683
  • 5
  • 42
  • 65
  • 1
    One option is to persist UTC time and then convert to local time on view. Or you can persist a separate timezone setting along with the UTC time and then display as – bryanmac Dec 29 '13 at 13:18
  • Agree with bryanmac. Save the time with UTC format and show it accordingly. – Tabrej Khan Dec 29 '13 at 13:24
  • Thanks for answers. Let me see, I store time in plist, and read it once, and then store it in NSDate. Due to this post http://stackoverflow.com/a/16560489/1040347 NSDate doesn't have timezone property – Aleksey Potapov Dec 29 '13 at 13:26
  • you never store a timezone so what do you expect? – Daij-Djan Dec 29 '13 at 13:44

1 Answers1

3

The date is stored in the property list as GMT time. Your timezone is "GMT+2", therefore "January 1, 2014 1:30:00 AM" is archived as

<plist version="1.0">
<dict>
    <key>time</key>
    <date>2014-01-01T23:30:00Z</date>
</dict>
</plist>

So there is no problem with the plist archive, it is independent of any timezone/locale settings ("Z" = "Zulu time" = GMT).

It is only the property list editor in Xcode, which displays the date according to your timezone and locale.

When you read the value into an NSDate object, it represents exactly this point of time. To present the value to the user, you have to use a NSDateFormatter, which converts the NSDate to an NSString representing this date/time according to the user's time zone.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • Thanks for answer. Yes, it has 2014-01-01T23:30:00Z format. But I don't get what do you want to tell. Should I use `NSTimeZone` ? – Aleksey Potapov Dec 29 '13 at 13:53
  • @BraveS: Also "January 1, 2014 1:30:00 AM GMT+2" is the *same point in time* as "Dec 31, 2013, 10:30 PM GMT-1". – Martin R Dec 29 '13 at 14:09
  • I should mentioned it before, but look, I have a formatter `self.customFormatter = [NSDateFormatter new]; [self.customFormatter setDateFormat:@"HH:mm a"];` then I convert to string using `[self.customFormatter stringFromDate:date]` But I didn't help – Aleksey Potapov Dec 29 '13 at 14:15
  • @BraveS: What result do you expect? "January 1, 2014 1:30:00 AM" in your timezone *is the same time* as "Dec 31, 2013, 10:30 PM" in your client's timezone. And note that the date format for 12hr time is "hh", not "HH". - Perhaps you can better explain what you are trying to do. Where does the date come from initially, how is it stored, etc ... – Martin R Dec 29 '13 at 14:25
  • @BraveS: So you want to store "1:30 AM" in the property list, and all clients should see "1:30 AM", regardless of their timezone? - In that case you could just store a string instead of a date. – Martin R Dec 29 '13 at 14:40
  • Martin, storing string in plist it's not properly. I want the client in one (-3GMT) timezone see one date, I instead see another – Aleksey Potapov Dec 29 '13 at 14:43
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/44096/discussion-between-martin-r-and-braves) – Martin R Dec 29 '13 at 14:44