Since plist is xml, which is text, when an NSDate object is written into a plist, the result is something like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<date>2011-04-01T02:09:15Z</date>
</plist>
I would like to obtain that string (011-04-01T02:09:15Z
) directly, without all the surroundings. There has to be a more sensible way to do it than:
NSString *xmlRepresentationOfCurrentDate = [[[[[[[NSString alloc] initWithData:[NSPropertyListSerialization dataFromPropertyList:self format:kCFPropertyListXMLFormat_v1_0 options:0 error:NULL] encoding:NSUTF8StringEncoding] autorelease] componentsSeparatedByString:@"<date>"] objectAtIndex:1] componentsSeparatedByString:@"</date>"] objectAtIndex:0];
What complicates it is the fact that the representation above is GMT, and apparently the timezone is set during the creation of the NSDate object. An alternative to the above code I see is to get the GMT offset, use it in the dateWithTimeInterval:sinceDate:
method to get the GMT date, and then use the NSDateFormatter
to write out the above string. However, since that has even more overhead.
Is there any way to get just that xml string?