Jump to content

Как перевести секунды в дату


Recommended Posts

 

Функция перевода секунд в удобный вид даты.

Параметры:

  • (int) time - количество секунд

Возвращаемая переменная:

  • объект класса NSString, содержащий в себе строку конвертированной даты.

Код:

- (NSString *)stringWithSeconds:(int)time {
int seconds = time%60;
time = time/60;
int minutes = time%60;
time = time/60;
int hours = time%24;
 int 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;
}

 

 

Статья подготовлена @ILYA2606

Link to post
Share on other sites
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...