iOS_NSDate,时间戳等
来源:互联网 发布:一个域名要多少钱 编辑:程序博客网 时间:2024/06/07 02:36
会出现2038问题。
addtime = 1410863909000;
要转换成iOS的时间戳要除以1000
NSString*String = [NSStringstringWithFormat:@"%f",1410863909000/1000]; NSTimeInterval time = [StringdoubleValue]; NSDateFormatter * formatter = [[NSDateFormatteralloc]init]; [formatter setDateStyle:NSDateFormatterMediumStyle]; [formatter setTimeStyle:NSDateFormatterShortStyle]; [formattersetDateFormat:@"yyyy-MM-dd HH:mm"];//yyyy-MM-dd HH:mmset [formatter setFormatterBehavior:NSDateFormatterBehavior10_4]; NSDate *timeDate = [NSDatedateWithTimeIntervalSince1970:time]; NSLog(@"pcl.addtime = %@",timeDate); NSString *timeStr = [formatterstringFromDate:timeDate]; NSLog(@"timeStr=%@",timeStr);
测试程序的效率:
/* 计算一个方法的效率 TICK在方法前调用 Tock在方法后调用*/#define TICK NSDate *startTime = [NSDate date]#define TOCK NSLog(@"Time: %f", -[startTime timeIntervalSinceNow])
获取当前时间
-(NSString*)getTodayDate{ NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *comps = [[NSDateComponents alloc] init]; NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; NSDate *now=[NSDate date]; comps = [calendar components:unitFlags fromDate:now]; //week = [comps weekday]; NSInteger year = [comps year]; NSInteger month = [comps month]; NSInteger day = [comps day]; NSString * dateStr = [NSString stringWithFormat:@"%04d%02d%02d",year,month,day]; return dateStr;}
计算周几:
// 计算出对应的一个星期的第几天- (NSInteger) getWeekDayWithStringDate:(NSString *) strdate { int year = [[strdate substringToIndex:4] intValue]; int month = [[[strdate substringFromIndex:4] substringToIndex:2] intValue]; int day = [[strdate substringFromIndex:6] intValue]; NSDateComponents *comps = [[[NSDateComponents alloc] init] autorelease]; [comps setDay:day]; [comps setMonth:month]; [comps setYear:year]; NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease]; NSDate *date = [gregorian dateFromComponents:comps]; NSDateComponents *weekdayComponents = [gregorian components:NSWeekdayCalendarUnit fromDate:date]; NSInteger weekday = [weekdayComponents weekday]; return weekday;}// 对应于哪一天- (NSString *) getWeekDayWithIntWeekday:(NSInteger) intweekday { switch (intweekday) { case 1: return LocalizedString(@"周日", @""); break; case 2: return LocalizedString(@"周一", @""); break; case 3: return LocalizedString(@"周二", @""); break; case 4: return LocalizedString(@"周三", @""); break; case 5: return LocalizedString(@"周四", @""); break; case 6: return LocalizedString(@"周五", @""); break; case 7: return LocalizedString(@"周六", @""); break; default: return nil; break; }}
0 0
- iOS_NSDate,时间戳等
- mongodb 时间类型 date 时间戳等
- 等时间~
- PHP 时间戳 日期 转换等问题
- js根据日期等生成时间戳
- 时间格式化,时间戳生成等工具方法
- 日期对象,判断天数,时间戳转换等时间处理
- 时间格式、比较等(3):时间戳的与时间的相互转化
- iOS 本地时间 / UTC时间 / 时间戳等操作 / 获取当前年月日
- PHP中关于时间(戳)、时区、本地时间、UTC时间等的梳理
- 等有时间
- 时间格式化等操作
- MongoDB 一些简单操作,_id ,时间戳等
- CString.Format大全 格式化时间戳等无符号整数
- python datetime模块相关 mysql 时间戳等
- iOS 时间戳转换为几分钟前等
- php中时间戳等相关小概念笔记
- python datetime模块相关 mysql 时间戳等
- 进程间通信_共享内存类_C++
- fopen vs access vs stat
- Ajax异步提交
- 第一章:绪论(思维导图)
- 小黑小波比.查询时判断是否又数据
- iOS_NSDate,时间戳等
- lettcode:twosum
- 鸟哥的私房菜:Bash shell(六)-管道命令
- POJ 1679 判断最小树是否唯一
- android 9.png 浅析
- LPC部分概念
- 自动化测试框架设计
- Chapter 11 Network Programming [《CSAPP》 笔记]
- 【iOS开发-7】UILabel类的用法以及实例化对象的各种属性介绍