代码如下:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
[formatter setTimeZone:timeZone];
NSDate *nowDate = [NSDate date];
NSInteger nowTime = [nowDate timeIntervalSince1970];
NSInteger waitTiem = nowTime - (1591871601675 / 1000);
NSLog(@"%@", [self getMMSSFromSS:waitTiem]);
// 下一分时间
NSInteger nextTime = (nowTime + 60) - (1591871601675 / 1000);
NSLog(@"%@", [self getMMSSFromSS:nextTime]);
}
#pragma mark 传入 秒 得到 xx:xx:xx
-(NSString *)getMMSSFromSS:(NSInteger )seconds{
NSString *str_hour = [NSString stringWithFormat:@"%02ld",seconds/3600];
NSString *str_minute = [NSString stringWithFormat:@"%02ld",(seconds%3600)/60];
NSString *format_time = nil;
format_time = [NSString stringWithFormat:@"%@:%@",str_hour,str_minute];
return format_time;
}
打印如下:
03:56 分钟+1即是03:57

网友评论