I am comparing the date when a file was last modified for two files, one local and one on Amazon S3 server. I am using the AWS IOS SDK framework and can successfully request and receive response from the S3 server but I have trouble understanding the format of the returned s3 date.
On my local machine the date format for lastModified is “2011-07-21 18:43:15 -0400” while for the file residing on the S3 server it is “2011-10-15T16:25:49.000Z”.
My local info is obtained using:
NSFileManager *fm = [NSFileManager defaultManager];
NSDictionary *attr = [fm attributesOfItemAtPath:filePath error:nil];
NSDate *localDate = [attr objectForKey:NSFileModificationDate];
while my S3 info is obtained using
for (S3ObjectSummary *object in [listObjectsResult objectSummaries]) {
NSDate *s3date = [object lastModified];
}
Does anyone know if I can convert the date for the S3 file to a format that I can use to compare these two dates using:
NSTimeInterval deltaSeconds = [s3Date timeIntervalSinceDate: localDate];
or am I doing something wrong here? Right now my program crashes with
[NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x200351360.
probably because the s3 date format is not in proper format. I am quite new to using the AWS S3 SDK so all help is greatly appreciated. If anyone also knows of some good tutorials for this framework (apart from the demo code that comes with it), that would be great. Cheers, Trond
It looks to me as
[object lastModified]simply returns aNSStringand not anNSDateobject, as stated in the documentation.NSDateFormattercan be used in this case to create aNSDateobject from the string:The Date Formatting guide has lots of handy examples. You may need to tweak the format string slightly as i have not tested it.