iOS获取应用当前Caches目录路径以及当前日期

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *path = [[paths objectAtIndex:0] stringByAppendingString:@"/hi.dat"];
    
    [[NSFileManager defaultManager] createFileAtPath:path contents:NULL attributes:NULL];
    
    NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
    NSLog(@"URL is: %@", url);
    [url release];

    NSDate *date = [NSDate dateWithTimeIntervalSinceNow:0.0];
    // 打印日期:中间的空格可以用'at'或'T'等字符来分隔
    NSDateFormatter *dateFomatter = [[NSDateFormatter alloc] init];
    [dateFomatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSLog(@"Current date is: %@", [dateFomatter stringFromDate:date]);
    [dateFomatter release];
posted @ 2014-07-22 16:37  zenny_chen  Views(2000)  Comments(0Edit  收藏  举报