惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Privacy & Cybersecurity Law Blog
Vercel News
Vercel News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
罗磊的独立博客
F
Fortinet All Blogs
T
Threatpost
Y
Y Combinator Blog
博客园_首页
美团技术团队
Security Latest
Security Latest
博客园 - 三生石上(FineUI控件)
T
Tailwind CSS Blog
V
V2EX - 技术
The Cloudflare Blog
L
LINUX DO - 热门话题
博客园 - 司徒正美
Jina AI
Jina AI
P
Proofpoint News Feed
宝玉的分享
宝玉的分享
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
WordPress大学
WordPress大学
The Hacker News
The Hacker News
P
Privacy International News Feed
T
The Exploit Database - CXSecurity.com
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
M
MIT News - Artificial intelligence
Latest news
Latest news
NISL@THU
NISL@THU
Google DeepMind News
Google DeepMind News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cisco Blogs
雷峰网
雷峰网
Application and Cybersecurity Blog
Application and Cybersecurity Blog
B
Blog RSS Feed
W
WeLiveSecurity
D
DataBreaches.Net
G
Google Developers Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
GRAHAM CLULEY
Spread Privacy
Spread Privacy
Know Your Adversary
Know Your Adversary
TaoSecurity Blog
TaoSecurity Blog
S
Securelist
Help Net Security
Help Net Security

博客园 - 英怀

获取当前页面url中的参数 coffeescript+node.js+angular 转 iphone开发资料汇总(很多实用的东东) 给状态条加上图标的代码 设置uiview背景图的方法之一 xcode 4 下找EXC_BAD_ACCESS错误原因 转--如何解决EXC_BAD_ACCESS错误 再转动画实现 关于Iphone开发得一些案例及常用知识(转过来的参考用) 用uiwebview打开pdf,word,excel 网络请求侦听工具 整理 被appstore 拒绝审核通过的原因 Capture iPhone Simulator Screenshots 将NSString转换编码集变为GBK或GB2312 转,ios开源程序集 在程序中如何把两张图片合成为一张图片 - 英怀 怎么让一个UIImageView响应点击事件呢 在model view中隐藏键盘代码 iphone view与view翻转的动画效果 使用NSUserDefaults保存简单的用户数据
object c 操作date类型
英怀 · 2011-07-22 · via 博客园 - 英怀

//得到当前的日期
NSDate *date = [NSDate date];
NSLog(@"date:%@",date);

//得到(24 * 60 * 60)即24小时之前的日期,dateWithTimeIntervalSinceNow:
NSDate *yesterday = [NSDate dateWithTimeIntervalSinceNow: -(24 * 60 * 60)];
NSLog(@"yesterday:%@",yesterday);

NSDateFormatter *formatter =[[[NSDateFormatter alloc] init] autorelease];
NSDate *date = [NSDate date];
[formatter setTimeStyle:NSDateFormatterMediumStyle];
NSCalendar *calendar = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDateComponents *comps = [[[NSDateComponents alloc] init] autorelease];
NSInteger unitFlags = NSYearCalendarUnit |
NSMonthCalendarUnit |
NSDayCalendarUnit |
NSWeekdayCalendarUnit |
NSHourCalendarUnit |
NSMinuteCalendarUnit |
NSSecondCalendarUnit;
//int week=0;
comps = [calendar components:unitFlags fromDate:date];
int week = [comps weekday];
int year=[comps year];
int month = [comps month];
int day = [comps day];
//[formatter setDateStyle:NSDateFormatterMediumStyle];
//This sets the label with the updated time.
int hour = [comps hour];
int min = [comps minute];
int sec = [comps second];
NSLog(@"week%d",week);
NSLog(@"year%d",year);
NSLog(@"month%d",month);
NSLog(@"day%d",day);
NSLog(@"hour%d",hour);
NSLog(@"min%d",min);
NSLog(@"sec%d",sec);

//得到毫秒
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
//[dateFormatter setDateFormat:@"hh:mm:ss"]
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"];
NSLog(@"Date%@", [dateFormatter stringFromDate:[NSDate date]]);
[dateFormatter release];

==========================================
方法一

NSDate* toDate1 = [ [ NSDate alloc] initWithString:@"2520-9-26 17:10:00 +0600" ];
NSTimeInterval distance = [ toDate1 timeIntervalSinceNow ];
NSTimeInterval iDat = distance / ( 86400 ) ;
NSLog( @" From now to %@ diff: %f ", [toDate1 description ], iDat );
[ toDate1 release ];

方法二
NSDate* toDate = [ [ NSDate alloc] initWithString:@"2009-9-29 0:0:00 +0600" ];
NSDate* startDate = [ [ NSDate alloc] init ];
NSCalendar* chineseClendar = [ [ NSCalendar alloc ] initWithCalendarIdentifier:NSGregorianCalendar ];

NSUInteger unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit |
NSSecondCalendarUnit | NSDayCalendarUnit
| NSMonthCalendarUnit | NSYearCalendarUnit;

NSDateComponents *cps = [ chineseClendar components:unitFlags fromDate:startDate toDate:toDate options:0];
NSInteger diffHour = [ cps hour ];
NSInteger diffMin = [ cps minute ];
NSInteger diffSec = [ cps second ];
NSInteger diffDay = [ cps day ];
NSInteger diffMon = [ cps month ];
NSInteger diffYear = [ cps year ];
NSLog( @" From Now to %@, diff: Years: %d Months: %d, Days; %d, Hours: %d, Mins:%d, sec:%d",
[toDate description], diffYear, diffMon, diffDay, diffHour, diffMin,diffSec );
[ toDate release ];
[ startDate release ];
[ chineseClendar release ];