Snail—OC学习之日期NSDate
2015-07-25 15:48
477 查看
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { //得到现在的时间 2015-07-25 07:31:34 格林尼治时间 NSDate * now = [NSDate date]; NSDate * now1 = [NSDate new]; //返回当前时间多少秒后的时间 NSDate * date1 = [NSDate dateWithTimeIntervalSinceNow:10]; //返回1970年多少秒后的时间 NSDate * date2 = [NSDate dateWithTimeIntervalSince1970:10]; //返回2001年多少秒后的时间 NSDate * date3 = [NSDate dateWithTimeIntervalSinceReferenceDate:10]; //返回一个 过去很久远的时间 0001-12-30 00:00:00 +0000 NSDate * date4 = [NSDate distantPast]; //返回一个 未来很久远的时间 4001-01-01 00:00:00 +0000 NSDate * date5 = [NSDate distantFuture]; //在指定日期上加时间 [now dateByAddingTimeInterval:3600]; //时间间隔 返回的是秒数 float NSTimeInterval s1 = [date1 timeIntervalSinceNow]; //与1970.1.1日距离的时间间隔 NSTimeInterval s2 = [date1 timeIntervalSince1970]; //与2001.1.1日距离的时间间隔 NSTimeInterval s3 = [date1 timeIntervalSinceReferenceDate]; //返回两个时间的间隔 NSTimeInterval s4 = [date1 timeIntervalSinceDate:now]; //比较两个日期大小 返回值跟字符串比较的返回值相同 NSComparisonResult [now compare:date2]; //查看系统时区 NSTimeZone * timeZone = [NSTimeZone systemTimeZone]; //得到所有时区 返回值是NSDictionary NSDictionary * dict = [NSTimeZone abbreviationDictionary]; //格式化对应的字母符号 /* y:年 M:月 d:日 H:时 m:分 s:秒 SS:毫秒 */ //利用时间戳来格式化输出时间 NSDateFormatter * formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat = @"yyyy年MM月dd日 HH:mm:s.SS"; //更改时区 formatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"HKT"]; NSLog(@"%@",[formatter stringFromDate:now]); } return 0; }
相关文章推荐
- UVa 11853 - Paintball(DFS)
- HDU 1302 The Snail
- http://blog.csdn.net/ooflywing/article/details/5616311
- HDU 2674-- N!Again【技巧】
- 最具体的历史centos下一个 postfix + extmail + dovecot + maildrop 安装注意事项2014更新
- HDU 5289 2015 Multi-University Training Contest 1 1002 RMQ+二分
- hdoj 2674 N!Again 【好题】
- Leetcode 11 Container With Most Water
- uva12546. LCM Pair Sum
- HDU 2473 Junk-Mail Filter (并查集的删除操作)
- 可笑的unsigned double http://blog.csdn.net/suhuaiqiang_janlay/article/details/6078034
- 动态规划,而已! CodeForces 433B - Kuriyama Mirai's Stones
- udp socket bind fail
- ZOJ 3675 Trim the Nails(bfs)
- 使用UltraISO制作启动盘装Windows系统详细教程
- AIX7.1+11.2.0.4RAC实施
- 如何提升 RailS 应用的性能?
- wait/waitpid函数使用
- hdu 1532 Drainage Ditches
- 第四篇:报错出现“Run-Time Check Failure #2-Stack around the variable 'p2240' was corrupted