Функция перевода секунд в удобный вид даты.
Параметры:
- (NSInteger) time — количество секунд
Возвращаемая переменная:
- объект класса NSString, содержащий в себе строку конвертированной даты.
- (NSString *)stringWithSeconds:(NSInteger)time {
NSInteger seconds = time % 60;
time = time / 60;
NSInteger minutes = time % 60;
time = time / 60;
NSInteger hours = time % 24;
NSInteger days = time / 24;
NSString *string;
if (days != 0) {
string = [NSString stringWithFormat:@"%d:%02d:%02d:%02d", days, hours, minutes, seconds];
} else if (hours != 0) {
string = [NSString stringWithFormat:@"%d:%02d:%02d", hours, minutes, seconds];
} else {
string = [NSString stringWithFormat:@"%02d:%02d", minutes, seconds];
}
return string;
}
Немає коментарів:
Дописати коментар