2012-03-21 3 views
0

현지 시간으로 오후 6시에 UIAlertNotification을 설정해야합니다. 시간은 오전 11시에 설정되고 현재 현지 시간대가 GMT + 6 : 00이므로 18:00 pm에 도착합니다. 그러나 다른 시간대에 따라 다를 수 있습니다. 오후 6 시가되기를 바래요. 아무도 나를 친절하게 도와 줄 수 있습니까? 감사.NSDateComponents TimeZone 관련

NSDateComponents *comps=[[[NSDateComponents alloc]init]autorelease]; 
    [comps setYear:[year intValue]]; 
    [comps setMonth:[month intValue]]; 
    [comps setDay:[day intValue]]; 
    [comps setHour:[@"11" intValue]];//6pm 
    [comps setMinute:0]; 
    [comps setMinute:0]; 
    [comps setTimeZone:[NSTimeZone localTimeZone]]; 
    NSCalendar *cal=[[[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar] autorelease]; 
    NSDate *date1=[[cal dateFromComponents:comps]retain]; 

// 현지 경고 코드

NSInteger minutesAhead = 0; 
    NSTimeInterval seconds = (60 * minutesAhead) * -1; 
    NSDate *actualFireDate = [date1 dateByAddingTimeInterval:seconds]; 
    NSMutableDictionary *dictC = [NSMutableDictionary dictionaryWithDictionary:userInfo]; 
    [dictC setObject:date1 forKey:@"PCOriginalReminderDate"]; 

    UILocalNotification *notification = [[UILocalNotification alloc] init]; 
    notification.fireDate = actualFireDate; 
    notification.alertBody = message; 
    notification.userInfo = dictC; 

    [[UIApplication sharedApplication] scheduleLocalNotification:notification]; 
    [notification release]; 

참고 : 나는 날짜를 인쇄 할 때

, 그것은 말한다 :

date = "2012-04-04 18:00:00 +0000"; 

내가 그것을 오전 11시는 것을 의미한다고 생각 GMT와 7 시간 추가 (그리니치 표준시 +7 일광 이후) 오후 18시.

답변

1

당신은 당신의 UILocalNotificationtimeZone property을 설정하려면 : fireDate에 지정된

날짜는이 속성의 값에 따라 해석됩니다. nil (기본값)을 지정하면 발 생 날짜가 절대 GMT 시간으로 해석되어 카운트 다운 타이머와 같은 경우에 적합합니다. 유효한 NSTimeZone 객체를이 속성에 할당하면 발 생일이 시간대가 변경 될 때 자동으로 조정되는 월 클럭 시간으로 해석됩니다. 이 경우에 적합한 예는 자명종이다.

사용자가 설정 그래서 경우 통지의 당신이 당신의 코드에서 생성 한 다음, 당신이 갈 수있을거야 그 timeZone[NSTimeZone localTimeZone]에 설정 시간에 fireDate.

+0

나는 모든 일을 올바르게하고 있다고 생각합니다. 전체 코드를 추가했습니다. 친절하게 내가 실수를하고있는 곳을 알려주십시오. – Ahsan

+0

"날짜를 인쇄 할 때"라고 말하면 어떤 날짜로 얘기하고 있습니까? 또한 알림의 'timeZone' 속성을 설정하지 않았습니다. – yuji