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 - iPhone 和 iPad 中的 SASS 后台问题

iphone - "self.navigationItem.rightBarButtonItem"不工作

objective-c - 如何使 NSWindow 只能垂直调整大小?

ios - NSDate希伯来语日期标签

ios - NSDateComponents 在模拟器上运行

iphone - OCUnit 和 OCMock 在 iPhone SDK 上工作吗?

iphone - 如何改善图像加载问题。有没有缓存之类的解决方案

css - Iphone 上奇怪的背景图像和边框错误

objective-c - 在 Objective-C 中使用 int 数据类型

core-data - '-[__NSDate ManagedObjectContext] : unrecognized selector sent to instance