• 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
Re: Carbon Date to NSDate - Here's How
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Carbon Date to NSDate - Here's How


  • Subject: Re: Carbon Date to NSDate - Here's How
  • From: email@hidden
  • Date: Tue, 26 Feb 2002 16:14:48 -0800

If you don't want to have such a cryptic constant in your code, you can
make the carbon epoch and use dateWithTimeIntervalSinceReferenceDate

+ (NSDate *)carbonEpoch
{
static NSCalendarDate *carbon_epoch;
if (carbon_epoch == nil)
carbon_epoch = [[NSCalendarDate dateWithYear:1904 month:1
day:1 hour:0 minute:0 second:0
timeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]] retain];
return carbon_epoch;
}

On Monday, February 25, 2002, at 03:36 PM, John Pattenden wrote:

> I ended up doing this
>
> myCorrectedDate = myCarbonDate - 0xB6757900;
>
> myCocoaDate = [NSDate dateWithTimeIntervalSinceReferenceDate:
> myCorrectedDate];
>
>
> 0xB6757900 is the hex difference between the carbon epoch and the
> standard cocoa epoch...
>
>
>> On Monday, February 25, 2002, at 11:20 AM, John Pattenden wrote:
>>
>>> I have a carbon app that sends a ulong date to my cocoa code, is
>>> there a simple way to convert from Carbon's date format to cocoas??
>>
>> Depending on just what the epoch is for that unsigned long, assuming
>> that value is seconds since the epoch, you can do it like this:
>>
>> unsigned long carbonDate;
>> double interval = carbonDate;
>>
>> NSDate myDate = [NSDate
>> dateWithTimeIntervalSinceReferenceDate:interval];
>>
>> or this:
>>
>> NSDate myDate = [NSDate dateWithTimeIntervalSince1970:interval];
>>
>> See which one works.
>>
>> HTH,
>>
>> -jcr
>>
>>
>> John C. Randolph <email@hidden> (408) 974-8819
>> Sr. Cocoa Software Engineer,
>> Apple Worldwide Developer Relations
>
>
> John Pattenden
> ScreenTime Media
>
> http://www.screentime.com
> _______________________________________________
> cocoa-dev mailing list | email@hidden
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Carbon Date to NSDate - Here's How
      • From: Andrew Pinski <email@hidden>
References: 
 >Re: Carbon Date to NSDate - Here's How (From: John Pattenden <email@hidden>)

  • Prev by Date: Re: Another filesystem mystery
  • Next by Date: Re: Can't find mysql.h
  • Previous by thread: Re: Carbon Date to NSDate - Here's How
  • Next by thread: Re: Carbon Date to NSDate - Here's How
  • Index(es):
    • Date
    • Thread