0

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];
}*
Community
  • 1
  • 1
  • possible duplicate of [How do I download and save a file locally on iOS using objective C?](http://stackoverflow.com/questions/5323427/how-do-i-download-and-save-a-file-locally-on-ios-using-objective-c) – jscs Nov 06 '11 at 18:50

1 Answers1

1

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.

Tim
  • 14,447
  • 6
  • 40
  • 63