首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >日期格式化

日期格式化
EN

Stack Overflow用户
提问于 2013-03-21 18:08:31
回答 1查看 56关注 0票数 0

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

代码语言:javascript
复制
  "1 day before",

但我想作为

代码语言:javascript
复制
  "At the time of event"

下面是我的代码,

代码语言:javascript
复制
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];

我的代码出了什么问题?有没有人能帮我整理一下?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-21 18:11:27

可能跟时区有关。您可能需要为NSDateFormatter object.Please的timeZone属性设置适当的值将时区设置为本地时区

代码语言:javascript
复制
[temp1 setTimeZone:[NSTimeZone systemTimeZone]];

(or)

[temp1 setTimeZone:[NSTimeZone localTimeZone]];

请将此代码放入:

代码语言:javascript
复制
 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];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15544513

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档