NSDate 问题】的更多相关文章

一.NSDate NSDate对象用来表示一个具体的时间点. NSDate是一个类簇,我们所使用的NSDate对象,都是NSDate的私有子类的实体. NSDate存储的是GMT时间,使用的时候会根据 当前应用 指定的 时区 进行时间上的增减,以供计算或显示. //iOS时间 //当前时间.默认0时区 NSDate *date = [NSDate date]; NSLog(@"当前时间date%@",date); //NSDateFormatter是用来设置NSDate的格式 NSDa…
========================== Foundation框架下的常用类 ========================== 一.[NSNumber] [注]像int.float.char.double等这种都是基础数据类型. [注]继承自C语言的基础变量类型(int,float,char.double等)不能被添加到数组和字典等oc专有的数据结构中.使用不方便,也不能通过添加类别等oc专有语法进行管理. [另]可以认为,NSNumber是基础类型数据转成对象类型数据的一个类.…
在项目中,我们可能会面对各种各样的对于时间的需求,在这里提供几种可能会用到的需求代码 1.与今天的时间做比较,返回日期差值 代码: - (NSInteger)compareWithToday { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; NSDate *today = [NSDate date]; NSString *…
//时间戳处理 NSInteger time = [self.album.updatedAt integerValue] / 1000; NSNumber *timer = [NSNumber numberWithInteger:time]; NSTimeInterval interval = [timer doubleValue]; NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval]; //设置日期格式 NSDateFo…
NSDate类用于保存时间值,同时提供了一些方法来处理一些基于秒级别时差(Time Interval)运算和日期之间的早晚比较等. 1. 创建或初始化可用以下方法 用于创建NSDate实例的类方法有 + (id)date; 返回当前时间 + (id)dateWithTimeIntervalSinceNow:(NSTimeInterval)secs; 返回以当前时间为基准,然后过了secs秒的时间 + (id)dateWithTimeIntervalSinceReferenceDate:(NSTi…
1. NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; [outputFormatter setLocale:[NSLocale currentLocale]]; [outputFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"]; NSLog(@"%@",[outputFormatter stringFromDate:[NSDate dat…
此方法用来计算当前时间与目标时间的先后顺序: -(NSDate *)calculateTimeWithCurrentTime:(NSDate *)currentDate{ //将当前时间转为本地时区 NSDate * currentLocalDate = [self localDateFromDate:currentDate]; NSLog(@"currentDate--->%@",currentLocalDate); //设置目标时间为当天15:30 NSString *dat…
NSDate:是OC中处理日期时间的一个类,可以用来表示时间 获取当前的时间 NSDate *d = [NSDate date]; 创建日期时间对象 NSLog输出是当前时间 格林时间 格式化显示时间 NSDate *d1 = [NSDate date]; NSLog(@"%@", d1); // 格式化日期,时间 // NSDateFormatter 日期格式化 /* yyyy 表示四位的年份 MM 表示2位的月份 dd 表示2位的天数 HH 表示24小时制的小时 hh 12小时制…
NSDate *date=[NSDate date]; NSDateFormatter *formatter=[[NSDateFormatter alloc]init]; formatter.dateFormat=@"yyy-MM-dd HH:mm:ss"; NSString *str=[formatter stringFromDate:date]; 字符串转化时间 NSString *time=@“2011/02/10 18:34”; NSDateFormatter *formatt…
Objective-c 之Foundation之NSNumber ,NSValue, NSDate 1.NSNumber具体用法如下: 在Objective-c中有int的数据类型,那为什么还要使用数字对象NSNumber.这是因为很多类(如NSArray)都要求使用对象,而int不是对象.NSNumber就是数字对象,我们可以使用NSNumber对象来创建和初始化不同类型的数字对象. 此外,还可以使用实例方法为先前分配的NSNumber对象设定指定的值,这些都是以initWith开头,比如in…