开发者

Local notification ,time setting

HI All,

i am trying to use local notification by using this

NSDateComponents *dateComps = [[NSDateComponents alloc] init];

[dateComps setDay: [dateComponents day]];
[date开发者_Go百科Comps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps setHour:[timeComponents hour]];  // Notification will fire in one minute

[dateComps setMinute:0 ];   //[timeComponents minute]];
[dateComps setSecond:60];   //[timeComponents second]];

and i hv string something like current time : 2011-03-26 11:59:31 GMT according to which i need to set sec,min, hours.

How can i set min, week,month, year etc, to pop up notification in above condition??

Guidenece needed.

Appreciate it


You can make a NSDateComponent from the above date as

NSDateComponents *components = [calendar components:(kCFCalendarUnitHour | kCFCalendarUnitMinute | kCFCalendarUnitSecond) fromDate:date];

NSInteger hour = [components hour];

NSInteger minute = [components minute];


If you want to set sec,min,hours etc. with this string "current time : 2011-03-26 11:59:31 GMT"

then first make a NSDate with this string using NSDateFormatter and get your values from this date.

NSString *dateStr = @"2011-03-26 11:59:31";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
NSDate *date = [dateFormat dateFromString:dateStr];  
[dateFormat setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
dateStr = [dateFormat stringFromDate:date]; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜