//时间转成时间戳
NSTimeZone *zone = [NSTimeZone defaultTimeZone];//获得当前应用程序默认的时区
NSInteger interval = [zone secondsFromGMTForDate:[NSDate date]];//以秒为单位返回当前应用程序与世界标准时间(格林威尼时间)的时差
NSDate *localeDate = [[NSDate date] dateByAddingTimeInterval:interval];
NSTimeInterval timeInterval2 = [localeDate timeIntervalSince1970];
NSLog(@"%f",timeInterval2);
//时间戳转成时间
NSTimeInterval timeInterval = [@"1350359820.211" doubleValue];
NSDate *date2 = [NSDate dateWithTimeIntervalSince1970:timeInterval];
NSLog(@" date2 -------------------- %@",date2);
//
- (NSString *)intervalSinceNow: (NSString *) theDate
{
NSDateFormatter *date=[[NSDateFormatter alloc] init];
[date setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *d=[date dateFromString:theDate];
NSTimeInterval late=[d timeIntervalSince1970]*1;
NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
NSTimeInterval now=[dat timeIntervalSince1970]*1;
NSString *timeString=@"";
NSTimeInterval cha=now-late;
if (cha/3600<<span style="color: rgb(140, 139, 252); ">1) {
timeString = [NSString stringWithFormat:@"%f", cha/60];
timeString = [timeString substringToIndex:timeString.length-7];
timeString=[NSString stringWithFormat:@"%@分钟前", timeString];
}
if (cha/3600>1&&cha/86400<<span style="color: rgb(140, 139, 252); ">1) {
timeString = [NSString stringWithFormat:@"%f", cha/3600];
timeString = [timeString substringToIndex:timeString.length-7];
timeString=[NSString stringWithFormat:@"%@小时前", timeString];
}
if (cha/86400>1)
{
timeString = [NSString stringWithFormat:@"%f", cha/86400];
timeString = [timeString substringToIndex:timeString.length-7];
timeString=[NSString stringWithFormat:@"%@天前", timeString];
}
[date release];
return timeString;
}