我能够解析我的文本文件,但现在将包含开始日期和结束日期的字符串转换为 NSDATE 的问题。
我还没有遍历整个文件,只是特定文件中的一行,一旦我至少可以格式化一行,我将遍历整个文件。
2013-06-08 00:00:00 +0000 and 2013-06-08 12:00:00 +0000
我目前已经通过追加和插入将0 和 1200 转换为。
这是我使用的代码。
NSData *data = [[NSData alloc] initWithData:downloadFile.receivedData];
NSString *dataString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSArray *components = [dataString componentsSeparatedByString:@"\n"];
NSString *anotherString = [NSString stringWithFormat:components[1]];
NSArray *times = [anotherString componentsSeparatedByString:@" "];
NSMutableString *startDate = [[NSMutableString alloc] initWithString:times[0]];
NSMutableString *endDate = [[NSMutableString alloc] initWithString:times[1]];
for (int i = startDate.length; i < 4; i++)
[startDate appendString:@"0"];
[startDate appendString:@":00 +0000"];
for (int i = endDate.length; i < 4; i++)
[endDate appendString:@"0"];
[endDate appendString:@":00 +0000"];
[startDate insertString:@":" atIndex:2];
[endDate insertString:@":" atIndex:2];
[startDate insertString:@"2013-06-08 " atIndex:0];
[endDate insertString:@"2013-06-08 " atIndex:0];
我意识到在添加事件时,我不需要知道结束时间只是时间间隔。因此,我计划将开始时间与结束时间进行比较,然后以这种方式找到时间间隔。
I understand the DATE i give my string is of a constant date but that isn't the issue at the moment, I'll fix that later. But for now I would like to convert the NSString *startDate I created and stored the date/time string in to an NSDate *startDate so that I can use it as the start dat of an EKEvent.
Thank you guys.