• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Time zone problem with CoreData
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Time zone problem with CoreData


  • Subject: Time zone problem with CoreData
  • From: Kevin Hoctor <email@hidden>
  • Date: Mon, 11 Feb 2008 19:15:35 -0600

I'm running into problems with storing dates in CoreData SQLite databases. I've tried to use GMT dates without times to keep the queries clean like this:

- (void)setDate:(NSDate *)value
{
// convert to calendar date so we can strip time and set GMT timezone
NSCalendarDate *c = [NSCalendarDate dateWithTimeIntervalSinceReferenceDate:[value timeIntervalSinceReferenceDate]];

[self willChangeValueForKey: @"date"];
[self setPrimitiveValue:[NSCalendarDate dateWithYear:[c yearOfCommonEra] month:[c monthOfYear] day:[c dayOfMonth] hour:0 minute:0 second:0 timeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]] forKey: @"date"];
[self didChangeValueForKey: @"date"];
}


The problem is that when the dates are retrieved, they are coming in with a local time zone causing the date to show as yesterday. It doesn't matter that I'm displaying the dates with a GMT time zone, the actual value from (NSDate *)date has the time zone.

I don't even want the time. What is the correct way to keep time zones out of the equation with CoreData?

Peace,

Kevin Hoctor
email@hidden
No Thirst Software LLC
http://nothirst.com
http://kevinhoctor.blogspot.com



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Time zone problem with CoreData
      • From: Nick Zitzmann <email@hidden>
  • Prev by Date: Linking to Embedded Carbon Framework
  • Next by Date: UPDATE: Core Data Cascade delete rule sometimes doesn't -- maybe never? (all of a sudden)
  • Previous by thread: Re: Linking to Embedded Carbon Framework
  • Next by thread: Re: Time zone problem with CoreData
  • Index(es):
    • Date
    • Thread