如何向NSDate对象添加月份?

NSDate *someDate = [NSDate Date] + 30Days.....;

推荐答案

您需要使用NSDateComponents:

NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
[dateComponents setMonth:1];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDate *newDate = [calendar dateByAddingComponents:dateComponents toDate:originalDate options:0];
[dateComponents release]; // If ARC is not used, release the date components

Ios相关问答推荐

使用UIGraphicsBeginIMAext创建新图像会扭曲图像 colored颜色

如何调整包含extView的UICollectionViewListCell的大小?

如何解释在SwiftUI视图中观察到持续的数据更改

_SKStoreProductParameterAdNetworkSourceIdentifier未定义符号

在 iOS 上启用明文本地流量在 .NET MAUI 中不起作用

使用按位|带有布尔操作数

错误:无法根据成员environmentObject推断上下文基础

具有多个目标的应用程序的动态内容

Swift 5.7 - 使存在的任何协议符合 Hashable

UIImageView 使用 CGAffineTransform 错误旋转

在 UICollectionView 上动态设置布局导致莫名其妙的 contentOffset 变化

iPhone iOS 无法正确显示 box-shadow

在 iOS 中获取设备位置(仅限国家/地区)

动画 UILabel 字体大小更改

无法将NSTaggedPointerString类型的值转换为NSNumber

如何使用 Contacts Framework 获取 iOS 9 中的所有联系人记录

UITextView 从文本的底部或中间开始

如何像在 Facebook 应用程序中一样以编程方式打开设置?

在 iOS 上存储身份验证令牌 - NSUserDefaults 与 keys 串?

为给定的 UIColor 获取更亮和更暗的 colored颜色 变化