//获取当前时间
- (NSString*)getCurrentTime {
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yy-MM-dd-HH-mm-ss"];
NSString *dateTime = [formatter stringFromDate:[NSDate date]];
self.currentTime = dateTime;
NSLog(@"当前时间是===%@",_currentTime);
return _currentTime;
}
//获取当前时间戳
- (NSString*)getCurrentTimestamp {
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:0];
NSTimeInterval timeInterval = [date timeIntervalSince1970];
NSString *timeString = [NSString stringWithFormat:@"%0.f", timeInterval];
//转为字符型 NSLog(@"当前时间戳是===%@",timeString);
return timeString;
}
//把时间戳转化为时间
-(NSString*)SetTime:(NSString*)time {
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"yy-MM-dd"];
int timeval = [time intValue];
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:timeval];
NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
return confromTimespStr;
}
网友评论