最好和更清潔的方法:
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"dd.MM.yyyy HH:mm:ss"];
for(int i=0; i < [DateTimeArray count]; ++i)
{
NSString *string = [DateTimeArray objectAtIndex:i];
NSDate *date = [df dateFromString:string];
[timeArray addObject:time];
}
[df release]; // ALWAYS release unused objects
再到剛剛接觸小時,而不是幾天,你應該選擇每個NSDate*
實例所需的組件:
// Get the Gregorian calendar
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
// Get the date
NSDate* date = [timeArray objectAtIndex:my_index];
// Get the hours, minutes, seconds
NSDateComponents* hour = [cal components:NSHourCalendarUnit fromDate:date];
NSDateComponents* minute = [cal components:NSMinuteCalendarUnit fromDate:date];
NSDateComponents* second = [cal components:NSSecondCalendarUnit fromDate:date];
@KingoofBliss ,非常感謝你 – Pooja 2011-05-23 10:29:32
@pooja:歡迎你:) – KingofBliss 2011-05-23 10:36:15
@KingofBliss,你能告訴我如何設置GMT + 1,因爲它顯示我在1小時前 – Pooja 2011-05-23 10:39:46