Objiective-C中的NSDate
来源:互联网 发布:怎样做淘宝淘宝课程 编辑:程序博客网 时间:2024/06/05 08:41
//得到当前的日期
// 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 = [[NSCalendaralloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDateComponents *comps = [[[NSDateComponentsalloc] init] autorelease];
NSInteger unitFlags = NSYearCalendarUnit l
NSMonthCalendarUnit l
NSDayCalendarUnit l
NSWeekdayCalendarUnit l
NSHourCalendarUnit l
NSMinuteCalendarUnit l
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 lable 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 = [[NSDateFormatteralloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
//[dateFormatter setDateFormat:@"hh:mm:ss"]
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"];
NSLog(@"Date@",[dateFormatter stringFormDate:[NSDate date]]);
[dateFormatter release];
- Objiective-C中的NSDate
- Object-C中的NSDate
- Object-C 中的日期(NSDate)
- Cocoa & Objiective-C Tutorial(教程网站)
- Objiective-C入门学习--------武器类
- No.03 Xcode(5.1.x) c,c++,objiective-c混编
- 17,Objective-C Foundation框架中的NSDate
- NSDate中的格式
- Foundation中的NSDate
- OC中的NSDate
- OC中的NSDate类
- OC中的时间NSDate
- OC中的NSDate
- objective-c NSDate
- Objective-C----NSDate、NSDateFormatter
- Objective-C 【NSDate】
- object c NSDate
- 获取NSDate中的某一项
- Ubuntu12.04安装matlab2014b
- 快速排序的一种java实现
- Java - 抽象类实现接口
- 理解矩阵(三)
- JSP入门教程
- Objiective-C中的NSDate
- centos7 安装 mariadb 的正确命令
- 关于Java中的I/O流的总结
- 将你的vim打造成轻巧强大的IDE
- 不止是产品经理(五)----启航
- c++对c的增强
- leetcode InsertionSort list
- @TargetApi(Build.VERSION_CODES.LOLLIPOP)报错
- linux下IPTABLES配置详解