2015-06-23 26 views

回答

1

你好,我懂了這個答案: -

NSDate *pickerDate = [NSDate date]; 
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; 
    [dateFormatter setDateFormat:DT_FORMATE_BIRTHDATE]; 
    NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:DT_TIME_ZONE_GMT]; 
    [dateFormatter setTimeZone:gmt]; 

    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; 
    NSDateComponents *timeComponents = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) 
                fromDate:pickerDate]; 
    [timeComponents setHour:9]; 
    [timeComponents setMinute:00]; 
    [timeComponents setSecond:0]; 

    NSDate *dtFinal = [calendar dateFromComponents:timeComponents]; 
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"]; 

    NSString *fierDate = [formatter stringFromDate:dtFinal]; 
+0

這裏是什麼'DT_TIME_ZONE_GMT'? – rptwsthi

+0

DT_TIME_ZONE_GMT = @「GMT」 –

0
  1. This是關於本地通知

  2. 下面是解決所屬時區的上面提及的問題進行了充分的教程。請詳細查看這些時區功能,並在您的功能中設置適當的時區。


[NSTimeZone defaultTimeZone] 

[NSTimeZone systemTimeZone] 

[NSTimeZone localTimeZone] 

NSTimeZone: what is the difference between localTimeZone and systemTimeZone?

+0

#Renish你是對的,但我需要爲每個時區設置默認時間,所以我得到了上面的Ans表單。謝謝你的回答。 –

+0

@mitulmarsonia,如果你得到用戶設備時區(獲取用戶設備時間!),那麼不需要更多的工作。你應該怎麼想? –

+0

設備時區變得容易,但我不知道如何設置我們的時間,所以我有這樣的問題。現在我瞭解瞭如何在任何時區設置我們的默認時間。 –

0

試試這個代碼。

NSDate *pickerDate = [date_picker date]; 
// Schedule the notification 
UILocalNotification* localNotification = [[UILocalNotification alloc] init]; 
localNotification.fireDate = pickerDate; 
localNotification.alertBody = @"Alert Body Message"; 
localNotification.alertAction = @"Alert Action Message"; 
localNotification.timeZone = [NSTimeZone defaultTimeZone]; 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];