我创建了一种将数据字符串写入文本文件的方法。我想知道如何获取系统日期和时间并将其发送到文本文件?这是方法:
-(void) writeToTextFile{
//get the documents dir
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//file name to write the data to using the documents directory:
NSString *fileName = [NSString stringWithFormat:@"%@/movbandlog.txt",
documentsDirectory];
//create content
NSString *content = @"Data received from device\n \n \n \n \nData sent to Portal\n \n \n \n \nData received to Portal";
//save to documents directory
[content writeToFile:fileName
atomically:NO
encoding:NSStringEncodingConversionAllowLossy
error:nil];
}