iphone - 在 iPhone 中查找周数

标签 iphone objective-c nsdate

这一定很简单,但我想不通。

我想在 iphone 中以 Integer 的形式查找周数。

这显示了如何获取字符串 Code

-(NSString*) getWeekOfMonth {
  NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
 [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
 [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
 [dateFormatter setDateFormat:@"W"];

 NSString *weekNumber = [dateFormatter stringFromDate:[NSDate date]];    
 [dateFormatter release];    
 return weekNumber;
}

谢谢

最佳答案

使用整数值:

NSInteger weekInt = [weekNumber integerValue];

关于iphone - 在 iPhone 中查找周数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7121651/

相关文章:

iPhone Icon@2x.png 未在 Retina 显示屏中显示

objective-c - 如何在 Cocoa 中进行异步 Web 服务调用

objective-c - Launchpad 使用哪个控件?

ios - Google Admob 无法使用 Objective-C 运行 Xcode 7.2

iphone - iPhone SDK中如何将从Sqlite数据库获取的数据转换为NSArray到NSData

iOS - 图标在启动时拉伸(stretch)

iphone - 为什么 UIWebView 实例不调用 scrollViewDidScroll?

iphone - 格式化 NSString(字符替换、UTF、...)

ios - 将 ISO8601 日期格式转换为本地时间 (iOS)

ios - dateFromString 一直返回 nil