ios NSDate NSTring long 时间戳与字符串转换
2013-12-01 15:31
417 查看
一,转化的方法为
NSString *timeSp = [NSString stringWithFormat:@"%d", (long)[localeDate timeIntervalSince1970]];
NSLog(@"timeSp:%@",timeSp); //时间戳的值
二,把获取的时间转化为当前时间
NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate:datenow];
NSDate *localeDate = [datenow dateByAddingTimeInterval: interval];
NSLog(@"%@", localeDate);
3.把时间戳转化为时间的方法
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:1363948516];
NSLog(@"1363948516 = %@",confromTimesp);
//timer
NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate:datenow];
NSDate *localeDate = [datenow dateByAddingTimeInterval: interval];
NSLog(@"%@", localeDate);
NSString *timeSp = [NSString stringWithFormat:@"%lld", (long long)[localeDate timeIntervalSince1970]];
NSLog(@"timeSp:%@",timeSp); //时间戳的值 1369189763711 1369218563 1369218614
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:1369189763711/1000];
NSLog(@"1363948516 = %@",confromTimesp);
//实例化一个NSDateFormatter对象
//判断昨天 前几天等 判断今天凌晨时间戳
NSDateFormatter *dateFormatter1 = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter1 setDateFormat:@"yyyy-MM-dd 00:00:00"];
NSString *currentDateStr1 = [dateFormatter1 stringFromDate:[NSDate date]];
NSLog(@"凌晨时间:%@",currentDateStr1);
NSString *timeSp1 = [NSString stringWithFormat:@"%lld", (long long)[localeDate timeIntervalSince1970]];
NSLog(@"凌晨时间戳:%@",timeSp1);
//昨天凌晨时间戳
NSString *timeSp2 = [NSString stringWithFormat:@"%lld", (long long)[localeDate timeIntervalSince1970]-24*60*60];
NSLog(@"昨天凌晨时间戳:%@",timeSp2);
NSString *timeSp = [NSString stringWithFormat:@"%d", (long)[localeDate timeIntervalSince1970]];
NSLog(@"timeSp:%@",timeSp); //时间戳的值
二,把获取的时间转化为当前时间
NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate:datenow];
NSDate *localeDate = [datenow dateByAddingTimeInterval: interval];
NSLog(@"%@", localeDate);
3.把时间戳转化为时间的方法
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:1363948516];
NSLog(@"1363948516 = %@",confromTimesp);
//timer
NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate:datenow];
NSDate *localeDate = [datenow dateByAddingTimeInterval: interval];
NSLog(@"%@", localeDate);
NSString *timeSp = [NSString stringWithFormat:@"%lld", (long long)[localeDate timeIntervalSince1970]];
NSLog(@"timeSp:%@",timeSp); //时间戳的值 1369189763711 1369218563 1369218614
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:1369189763711/1000];
NSLog(@"1363948516 = %@",confromTimesp);
//实例化一个NSDateFormatter对象
//判断昨天 前几天等 判断今天凌晨时间戳
NSDateFormatter *dateFormatter1 = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter1 setDateFormat:@"yyyy-MM-dd 00:00:00"];
NSString *currentDateStr1 = [dateFormatter1 stringFromDate:[NSDate date]];
NSLog(@"凌晨时间:%@",currentDateStr1);
NSString *timeSp1 = [NSString stringWithFormat:@"%lld", (long long)[localeDate timeIntervalSince1970]];
NSLog(@"凌晨时间戳:%@",timeSp1);
//昨天凌晨时间戳
NSString *timeSp2 = [NSString stringWithFormat:@"%lld", (long long)[localeDate timeIntervalSince1970]-24*60*60];
NSLog(@"昨天凌晨时间戳:%@",timeSp2);
相关文章推荐
- ios NSDate NSTring long 时间戳与字符串转换
- iOS NSDateFormatter将一串字符串转换成时间格式
- iOS 开发中常用到的关于时间戳,UTC时间,时间字符串,NSDate的互相转换
- iOS时间戳字符串NSdate转换demo
- iOS ISO8601格式的时间日期字符串转换成NSDate
- 时间字符串string转换为时间格式nsdate
- iOS如何将时间字符串转换成NSDate
- IOS将字符串转换为日期时间格式
- JS时间和字符串的相互转换 Date+String
- iOS NSDateFormatter 和 NSDate简单使用 时间戳的转换
- iOS积累--字符串转化为NSDate, 获取当前时区的系统时间
- Java 日期时间 Date类型,long类型,String类型表现形式的转换
- iOS将字符串转换为日期时间格式
- 时间DateTime类型转换为字符串String格式方法汇总
- iOS-字符串转化成NSDate类型 计算与当前时间的相差 月数 天数
- Java 日期时间 Date类型,long类型,String类型表现形式的转换
- Java String,long,Date时间格式相互转换
- IOS-时间与字符串互相转换
- XZ_iOS之时间戳和时间字符串的一个转换
- Java 日期时间 Date类型,long类型,String类型表现形式的转换