}
2.NSDate转换成时间戳
NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
NSString *timeSp = [NSString stringWithFormat:@"%d", (long)[datenow timeIntervalSince1970]];
NSLog(@"timeSp:%@",timeSp); //时间戳的值时间戳转时间的方法
//NSString 转 NSDate
+(NSDate *)dateWithString:(NSString *)dataString
{
NSDateFormatter * format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate * date = [format dateFromString:[self getCurrentDate]];
return date;
}
//NSDate 转 NSString
+(NSString *)stringWithDate:(NSDate *)date{
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString*strDate = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"%@",strDate);
[dateFormatter release];
return strDate;
}