PDA

View Full Version : Cannot write current time & date to a file




ilx.mac
Aug 4, 2009, 03:00 PM
Hi there,

I want to save the current date & time to a .txt file. I am getting the current time by :

CFAbsoluteTime myCurrentTime = CFAbsoluteTimeGetCurrent();

and i am writing it to the file:


paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
documentsDirectory = [paths objectAtIndex:0];
filePath = [documentsDirectory stringByAppendingPathComponent:@"log.txt"];
[filePath retain];
[myCurrentTime writeToFile:filePath atomically:YES encoding:NSASCIIStringEncoding error:NULL];


My IDE throws an error : Invalid Receiver Type CFAbsoluteTime.

Is there a way that I can write the datetime to my file?
(the string format is allowed to write file. But its here as CFAbsoluteTime)

Thanks in advance!:)



kainjow
Aug 4, 2009, 03:10 PM
CFAbsoluteTime is not an object. It's a double. You need to convert it to an NSString or NSData first.

PhoneyDeveloper
Aug 4, 2009, 03:23 PM
Remember that you can use stdio in Objective-C apps with no difficulties. Just use a full path for the fopen call.

fopen
fwrite
fclose