Cannot write current time & date to a file

Discussion in 'iOS Programming' started by ilx.mac, Aug 4, 2009.

  1. ilx.mac macrumors member

    Joined:
    Mar 10, 2009
    #1
    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!:)
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    CFAbsoluteTime is not an object. It's a double. You need to convert it to an NSString or NSData first.
     
  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    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
     

Share This Page