2

I want set notification default 9:00 am for every user timezone time.

How to create fire date for default time 9:00 am.

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
Mitul Marsoniya
  • 5,272
  • 4
  • 33
  • 57

3 Answers3

1

Hello I got it this Ans:-

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];
Mitul Marsoniya
  • 5,272
  • 4
  • 33
  • 57
0
  1. This is a full tutorial regarding Local Notification

  2. Below is Solve issue of timezone which mention above. Please review these timezone function in details and set appropriate timezone in your function.


[NSTimeZone defaultTimeZone]

[NSTimeZone systemTimeZone]

[NSTimeZone localTimeZone]

NSTimeZone: what is the difference between localTimeZone and systemTimeZone?

Community
  • 1
  • 1
Renish Dadhaniya
  • 10,642
  • 2
  • 31
  • 56
  • #Renish You are right but i need set default time for every timezone so i got Ans form above. Thank you for Ans. – Mitul Marsoniya Jun 23 '15 at 10:23
  • @mitulmarsonia, if you get user device timezone(Get User Device time!) then no need more work. What should you think? – Renish Dadhaniya Jun 23 '15 at 10:43
  • device timezone get easy but i dont know how to set our time in this so i have this kind of question. Now i got it how to set our default time in any time zone. – Mitul Marsoniya Jun 23 '15 at 10:47
0

Try this code.

 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];
Om Prakash
  • 9,191
  • 1
  • 12
  • 20