0

在使用以下格式在日历中添加事件时,它在日历警报中添加为:

  "1 day before",

但我想作为

  "At the time of event"

这是我的代码,

calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSString *cday,*cmonth,*cyear;
// set today
today = [[NSDate alloc] initWithTimeIntervalSinceNow:1];
//set the current day to show the calendar
NSDateFormatter *temp1 = [[NSDateFormatter alloc] init];
[temp1 setDateFormat:@"dd"];
cday=[temp1 stringFromDate:today];
NSLog(@"Date checking%@",cday);
[temp1 release];

我的代码有什么问题吗?谁能帮我解决一下。

4

1 回答 1

0

可能与时区有关。您可能需要为您的 NSDateFormatter 对象的 timeZone 属性设置适当的值。请将时区设置为本地时区

[temp1 setTimeZone:[NSTimeZone systemTimeZone]];

(or)

[temp1 setTimeZone:[NSTimeZone localTimeZone]];

请输入此代码:

 NSCalendar  *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSString *cday,*cmonth,*cyear;
    // set today
    NSDate *today = [NSDate date];
    //set the current day to show the calendar
    NSDateFormatter *temp1 = [[NSDateFormatter alloc] init];
   [temp1 setTimeZone:[NSTimeZone localTimeZone]];
    [temp1 setDateFormat:@"dd"];
    cday=[temp1 stringFromDate:today];
    NSLog(@"Date checking%@",cday);
    [temp1 release];
于 2013-03-21T10:11:26.573 回答