Query for date time calculation.

Discussion in 'Mac Programming' started by newformac, May 27, 2011.

  1. macrumors regular

    Joined:
    May 24, 2011
    #1
    Hi all,

    i m creating a file that contains date time and current locale,
    and after creating the file when application start read the file and calculate the time difference from file time to currently running time.

    Code:
    
    //Install Date/Time Reference File
    	NSFileManager *fileManager = [NSFileManager defaultManager];
    	NSString *installDateFile = @"~/Desktop/setlDateFile.txt";
    	installDateFile = [installDateFile stringByExpandingTildeInPath];
    	if ([fileManager fileExistsAtPath: installDateFile] == NO)
    		{
    		NSString *installDate = [[NSDate date] descriptionWithCalendarFormat:nil timeZone:nil locale:nil];
    		[installDate writeToFile:installDateFile atomically:YES encoding:NSUnicodeStringEncoding error:NULL];
    		}
    
    double secondsUsed = [[NSDate date] timeIntervalSinceDate:[NSDate dateWithString:[NSString stringWithContentsOfFile:[@"~/Desktop/setlDateFile.txt" stringByExpandingTildeInPath]]]];
    	
    
    

    now i want to write only date value in file and calculate the days difference from file date to current date.

    please help me how can i do this.

    thanks in advance.
     
  2. macrumors 68000

    Sydde

    Joined:
    Aug 17, 2009
    #2
    You should look at NSKeyedArchiver (for writing to the file) and NSKeyedUnarchiver (for reading back). You can encode/decode the actual NSDate object itself instead of converting it to a string, that way the user will have a much harder time altering its value and you can easily localize it after decoding.
     
  3. macrumors 68040

    Joined:
    Feb 2, 2008
    #3
    Doesn't files default to adding creation date/modification date on HFS? You should be able to read these with NSFileManager AFAIK.
     
  4. macrumors regular

    Joined:
    Jan 27, 2011
    #4
    The OP needs gentle nudging from us to learn to use the developer docs for most of his/her questions.
     
  5. thread starter macrumors regular

    Joined:
    May 24, 2011
    #5
    thanks for guidance.
     

Share This Page