PDA

View Full Version : Query for date time calculation.




newformac
May 27, 2011, 03:03 AM
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.



//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.



Sydde
May 27, 2011, 02:53 PM
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.

subsonix
May 27, 2011, 03:30 PM
Doesn't files default to adding creation date/modification date on HFS? You should be able to read these with NSFileManager AFAIK.

ehoui
May 27, 2011, 03:42 PM
The OP needs gentle nudging from us to learn to use the developer docs for most of his/her questions.

newformac
Jun 9, 2011, 11:40 PM
thanks for guidance.