//获取当前的时间
+(NSString*)getCurrentTimes{
NSDate *datenow = [NSDate date];
//----------将nsdate按formatter格式转成nsstring
NSString *currentTimeString = [formatter stringFromDate:datenow];
NSLog(@"currentTimeString = %@",currentTimeString);
return currentTimeString;
}
获取当前时间戳有两种方法(以秒为单位)
+(NSString *)getNowTimeTimestamp{
NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]];
return timeSp;
}
+(NSString *)getNowTimeTimestamp2{
NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
NSTimeInterval a=[dat timeIntervalSince1970];
NSString*timeString = [NSString stringWithFormat:@"%0.f", a];//转为字符型
;
return timeString;
}
//获取当前时间戳 (以毫秒为单位)
+(NSString *)getNowTimeTimestamp3{
NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)([datenow timeIntervalSince1970]*1000)];
return timeSp;
}