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

newformac

macrumors regular
Original poster
May 24, 2011
107
0
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.
 
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.
 
Doesn't files default to adding creation date/modification date on HFS? You should be able to read these with NSFileManager AFAIK.
 
The OP needs gentle nudging from us to learn to use the developer docs for most of his/her questions.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.