views:

30

answers:

1

I'm trying to extract the year from MPMediaItemPropertyReleaseDate in an MP3 file using iOS SDK 4.0 but it seems to always return Jan 1 1801 for the date. Does anyone know how to properly extract that from the returned NSDate? Here's what I'm doing:


NSString *locale = [[NSLocale currentLocale] localeIdentifier];
NSLog([[mediaItem valueForProperty:MPMediaItemPropertyReleaseDate] descriptionWithLocale: locale]);
// Always showing Thursday, January 1, 1801 2:15:58 AM GMT-4:56

Thanks in advance.

A: 

I would decompose the log statement. You're cutting corners that could lead to errors. Get the raw NSDate object and print a description of that without locale and see if you're still getting the same problem. If so, the problem might be the value in the file itself. Certainly, January 1, 1801 looks like a placeholder value of some kind.

As an aside, it is bad practice to call NSLog with just a string. NSLog expects the first value to be a format string and will interpret it as such. Any possible formatting charaters in string will be interpreted as format instead of data. Always use:

NSLog(@"%@",anObject);

... with the format string. It tedious but safer.

TechZen