Reputation: 1
Coding was found here! Hi all. In objective C, I am trying to download a file from the net and save it, however I also a require a time stamp! dd'mm'yy format! Can anyone help?
N*SString*stringURL =@"http://www.somewhere.com/thefile.png";
NSURL *url =[NSURL URLWithString:stringURL];
NSData*urlData =[NSData dataWithContentsOfURL:url];
if( urlData )
{
NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory =[paths objectAtIndex:0];
NSString *filePath =[NSString stringWithFormat:@"%@/%@", documentsDirectory,@"filename.png"];
[urlData writeToFile:filePath atomically:YES];
}*
Upvotes: 0
Views: 1420
Reputation: 14446
You can use this to get a timestamp as a string
NSDateFormatter *inFormat = [[NSDateFormatter alloc] init];
[inFormat setDateFormat:@"dd\\'MM\\'yy"];
NSString *parsed = [inFormat stringFromDate:[NSDate date]];
[inFormat release];
Not sure about the apostrophes, though. There may be cleaner ways instead of using the alloc
calls but this should work and won't leak.
Upvotes: 1