开发者

Convert milliseconds to minutes [closed]

开发者 https://www.devze.com 2023-03-06 17:21 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifyi开发者_JS百科ng this question so that it can be reopened, visit the help center. Closed 11 years ago.

How I can convert milliseconds to minutes or hours, in Objective-C or C?


Just use simple division. Use floating point numbers so that you don't lose precision from rounding.

float milliseconds = 966000.0;
float seconds = milliseconds / 1000.0;
float minutes = seconds / 60.0;
float hours = minutes / 60.0;


#define MSEC_PER_SEC    1000L
#define SEC_PER_MIN     60
#define MIN_PER_HOUR    60

int msec = 966000;
int min  = msec / (MSEC_PER_SEC * SEC_PER_MIN);
int hr   = min  / (MIN_PER_HOUR);


sounds a bit like a joke but what the heck…

  • divide by 60*1000… for minutes.
  • divide by 60*60*1000… for hours.

the beauty of it it works in all programming languages.


Divide by 1000 to get seconds. Divide seconds by 60 to get minutes.

0

精彩评论

暂无评论...
验证码 换一张
取 消