Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ilx.mac

macrumors member
Original poster
Mar 10, 2009
63
0
Hi there,

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

Code:
CFAbsoluteTime myCurrentTime = CFAbsoluteTimeGetCurrent();

and i am writing it to the file:


Code:
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!:)
 
CFAbsoluteTime is not an object. It's a double. You need to convert it to an NSString or NSData first.
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.