sách gpt4 ai đã đi

iphone - 获取 NSDate 今天、昨天、本周、上周、本月、上个月...变量

In lại 作者:行者123 更新时间:2023-12-03 18:08:37 26 4
mua khóa gpt4 Nike

我想做的是让 NSDate 今天、昨天、本周、上周、本月、上个月变量准备好进行比较,以便在 UITableView 的 titleForHeaderInSection 上添加标题

我想要的是在下面的代码中手动完成日期 2009-12-11

 NSDate *today = [NSDate dateWithString:@"2009-12-11 00:00:00 +0000"];
NSDate *yesterday = [NSDate dateWithString:@"2009-12-10 00:00:00 +0000"];
NSDate *thisWeek = [NSDate dateWithString:@"2009-12-06 00:00:00 +0000"];
NSDate *lastWeek = [NSDate dateWithString:@"2009-11-30 00:00:00 +0000"];
NSDate *thisMonth = [NSDate dateWithString:@"2009-12-01 00:00:00 +0000"];
NSDate *lastMonth = [NSDate dateWithString:@"2009-11-01 00:00:00 +0000"];

1 Câu trả lời

改编自Date and Time Programming Guide :

// Right now, you can remove the seconds into the day if you want
NSDate *today = [NSDate date];

// All intervals taken from Google
NSDate *yesterday = [today dateByAddingTimeInterval: -86400.0];
NSDate *thisWeek = [today dateByAddingTimeInterval: -604800.0];
NSDate *lastWeek = [today dateByAddingTimeInterval: -1209600.0];

// To get the correct number of seconds in each month use NSCalendar
NSDate *thisMonth = [today dateByAddingTimeInterval: -2629743.83];
NSDate *lastMonth = [today dateByAddingTimeInterval: -5259487.66];

如果您想要根据月份获得正确的确切天数,则应使用 NSCalendar .

关于iphone - 获取 NSDate 今天、昨天、本周、上周、本月、上个月...变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1889164/

26 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com