【发布时间】:2014-05-08 08:33:15
【问题描述】:
我正在尝试使用 NSDate,但它对我不起作用,我现在很困惑。所以我想要的基本东西是可行的,但它必须是今天,而不是从 2000 年开始。
所以我想要的是日期应该是今天的日期以及我的字符串 bU 和 eU 中的小时数,而不是 2000 年的日期和我的字符串小时数。
这是我的一段代码:
NSDate *localNotDate;
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setTimeZone:[NSTimeZone localTimeZone]];
[df setDateFormat:@"HH:mm"];
NSDate *bU = [df dateFromString:[[[self alarmArray] objectAtIndex:arrayInt] beginUur]]; // This is a 24:00 format string
NSDate *eU = [df dateFromString:[[[self alarmArray] objectAtIndex:arrayInt] eindUur]]; // This is a 24:00 format string
if (intForInsideForLoop == 0) { // Setup NSDate on first loop.
localNotDate = bU; // This gives the date 2000-01-01 08:24
}
if (intForInsideForLoop < timesOnDay) {
localNotDate = [localNotDate dateByAddingTimeInterval:(interval * 60)]; // Adds minutes to the date of today.
NSDateFormatter *dtest = [[NSDateFormatter alloc] init];
[dtest setTimeZone:[NSTimeZone localTimeZone]];
[dtest setDateFormat:@"yyyy-MM-dd HH:mm"];
NSLog(@"%@", [dtest stringFromDate:localNotDate]); // This gives the date 2000-01-01 08:24. it should be like It's Today thursday so 2014-05-08 08:24
}
【问题讨论】:
-
或许你可以使用stackoverflow.com/a/20441330/1187415的第一部分。
-
谢谢你的工作!
标签: ios objective-c nsdate