首页 > 其他 > 详细

NSDate

时间:2015-06-05 00:36:31      阅读:244      评论:0      收藏:0      [点我收藏+]

#pragma mark dateCreate

void dateCreate(){

NSDate  *date=[NSDate date];//调用当前时间 now

技术分享

//返回以当前时间为基准,然后过了secs秒时间。

date=[NSDate  dateWithTimeIntervalSinceNow:10];//TimeInterval 是秒

//会比当前时间快10s

//基准为1970-1-1 00:00:00 然后过了secs秒时间

date=[NSDate  dateWithTimeIntervalSince1970:10];

//随机返回一个未来的时间

date=[NSDate distanceFuture];

//随机返回以前的某个时间

date=[NSDate distancePast];

NSLog(@”%@”,date);

}

#pragme mark 取回时间间隔

void dateUse(){

NSDate  *date=[NSDate date];

//返回1970走过的毫秒数

NSTimeInterval interval = [date timeIntervalSince1970];

//跟其他时间进行对比

NSDate date1=[NSDate dateWithTimeIntervalSinceNow:20];

[date timeIntervalSinceDate:date1];

//日期比较

NSDate *early=[date earlierDate:date1];//返回比较早的时间

NSDate *late=[date laterDate:date1];//返回比较晚的时间

技术分享

}


void dateFormat(){

NSDate *date=[NSdate date];

//2015-6-4 22:48:45

NSDateFormatter *formatter=[[NSDateFormatter  alloc]init];

//HH是24进制,hh是12进制

formatter.dateFormat=@”yyyy-MM-dd HH:mm:ss”;

//设置时区

formatter.locale=[[[NSLocale alloc]WithLocaleIdentinitifier:@”zh_CN“]autorelease];

NSString *str=[formatter stringFromDate:date]; //date->string

NSlog(@”%@”,string);

//返回的是格林治时间

NSDate *date2=[formatter dateFromString:@“2015-6-4 22:51:34”];

NSLog(@”%@”,date2);

[formatter release];

//NSCalendor

}

NSDate

原文:http://www.cnblogs.com/yesihoang/p/4553343.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!