【问题标题】:Adding a time stamp to an Objective C URL save as?将时间戳添加到目标 C URL 另存为?
【发布时间】:2011-12-22 21:57:41
【问题描述】:

Coding was found here! 大家好。 在目标 C 中,我试图从网上下载一个文件并保存它,但是我还需要一个时间戳! dd'mm'yy 格式! 谁能帮忙?

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];
}*

【问题讨论】:

标签: objective-c ios xcode timestamp


【解决方案1】:

您可以使用它来获取字符串形式的时间戳

NSDateFormatter *inFormat = [[NSDateFormatter alloc] init];
[inFormat setDateFormat:@"dd\\'MM\\'yy"];

NSString *parsed = [inFormat stringFromDate:[NSDate date]];
[inFormat release];

但不确定撇号。可能有更简洁的方法而不是使用 alloc 调用,但这应该可以工作并且不会泄漏。

【讨论】:

  • [NSDate date] 是另一种选择。 NSDateFormatter 没有等效项。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-21
  • 2010-10-26
  • 2014-03-18
  • 1970-01-01
  • 2015-03-09
  • 2011-01-10
相关资源
最近更新 更多