Objective-c_Date 日期对象
2016-04-29 23:50
381 查看
NSDate *date = [NSDate
date];
NSLog(@"%@",date);
NSLog(@"%@",[date
descriptionWithLocale:[NSLocale
currentLocale]]);
NSDate *date1 = [NSDate
dateWithTimeIntervalSince1970:60*60*12];
NSLog(@"%@",[date1
descriptionWithLocale:[NSLocale
currentLocale]]);
NSDate *date2 = [NSDate
distantFuture];
NSLog(@"%@",date2);
NSLog(@"%@",[date2
descriptionWithLocale:[NSLocale
currentLocale]]);
NSDate *date3 = [NSDate
distantPast];
NSLog(@"%@",[date3
descriptionWithLocale:[NSLocale
currentLocale]]);
//NSDate的比较
NSDate *later= [date3
laterDate:date2];
NSLog(@"%@",[later
descriptionWithLocale:[NSLocale
currentLocale]]);
NSDate *earlier = [date3
earlierDate:date2];
NSLog(@"%@",[earlier
descriptionWithLocale:[NSLocale
currentLocale]]);
NSTimeInterval sc = [date
timeIntervalSinceNow];
NSDate *currentDate = [[NSDate
alloc]initWithTimeIntervalSinceNow:sc];
NSLog(@"%@",currentDate);
//NSDate和字符串的转换
NSDateFormatter *df = [[NSDateFormatter
alloc]init];
df.dateFormat =
@"yyyy-MM-dd hh:mm:ss";
//[df setDateFormat:@"yyyy年MM月dd日
HH小时mm分ss秒"];
NSString *na = [df
stringFromDate:date];
NSLog(@"系统当前时间为:%@",na);
//取出日期中的年、月、日、时、分、秒
NSCalendarDate *calendar = [NSCalendarDate
calendarDate];
int year = [calendar
yearOfCommonEra];
int month = [calendar
monthOfYear];
int day = [calendar
dayOfMonth];
NSLog(@"%4d-%02d-%02d",year,month,day);
date];
NSLog(@"%@",date);
NSLog(@"%@",[date
descriptionWithLocale:[NSLocale
currentLocale]]);
NSDate *date1 = [NSDate
dateWithTimeIntervalSince1970:60*60*12];
NSLog(@"%@",[date1
descriptionWithLocale:[NSLocale
currentLocale]]);
NSDate *date2 = [NSDate
distantFuture];
NSLog(@"%@",date2);
NSLog(@"%@",[date2
descriptionWithLocale:[NSLocale
currentLocale]]);
NSDate *date3 = [NSDate
distantPast];
NSLog(@"%@",[date3
descriptionWithLocale:[NSLocale
currentLocale]]);
//NSDate的比较
NSDate *later= [date3
laterDate:date2];
NSLog(@"%@",[later
descriptionWithLocale:[NSLocale
currentLocale]]);
NSDate *earlier = [date3
earlierDate:date2];
NSLog(@"%@",[earlier
descriptionWithLocale:[NSLocale
currentLocale]]);
NSTimeInterval sc = [date
timeIntervalSinceNow];
NSDate *currentDate = [[NSDate
alloc]initWithTimeIntervalSinceNow:sc];
NSLog(@"%@",currentDate);
//NSDate和字符串的转换
NSDateFormatter *df = [[NSDateFormatter
alloc]init];
df.dateFormat =
@"yyyy-MM-dd hh:mm:ss";
//[df setDateFormat:@"yyyy年MM月dd日
HH小时mm分ss秒"];
NSString *na = [df
stringFromDate:date];
NSLog(@"系统当前时间为:%@",na);
//取出日期中的年、月、日、时、分、秒
NSCalendarDate *calendar = [NSCalendarDate
calendarDate];
int year = [calendar
yearOfCommonEra];
int month = [calendar
monthOfYear];
int day = [calendar
dayOfMonth];
NSLog(@"%4d-%02d-%02d",year,month,day);
相关文章推荐
- iOS-Effective Objective-C 2.0 读书笔记(三)
- JSONObject简介
- iOS笔记---- object-c 分类
- 警告:object file was built for newer iOS version (8.3) than being linked (7.0)
- 深入理解JavaScript系列(12):变量对象(Variable Object)
- 9. ES5 之 Object.defineProperty(obj, prop, descriptor)
- addTarget参数含义||addTarget: action: forControlEvents:
- Objective-C runtime的常见应用
- Objective-C中 Self和 Super详解
- 在ASP.NET 2.0中操作数据之六:编程设置ObjectDataSource的参数值
- 浅谈objective-c
- objc_setAssociatedObject 使用(转)
- Caused by: java.lang.NullPointerException: Attempt to write to field 'int android.app.Fragment.mNextAnim' on a null object reference
- QMetaObject::invokeMethod: No such method的问题
- Map<String, ?>和Map<String, Object>的区别
- Objective-C runtime的常见应用
- Object-C高级编程读书笔记(6)—— GCD的一些函数
- OBJ-C实例变量修饰符;私有变量;私有方法;description;多态;点语法学习笔记
- OBJ-C组合模式学习笔记
- Hibernate之deleted object would be re-saved by cascade 异常的解决