-2

我有两个 linux 时间戳 begine-time 和 expire-time,我想以小时、分钟秒为单位计算这两个时间戳之间的差异。

语言:目标 C

“过期时间”:“1366927200”,“开始时间”:“1327532400”,

4

1 回答 1

-2
int beginTime = 1327532400;
int expireTime = 1366927200;
int diff = expireTime - beginTime;

#define SEC_PER_MIN 60
#define SEC_PER_HOUR (SEC_PER_MIN * 60)
#define SEC_PER_DAY (SEC_PER_HOUR * 24)

int days = diff / SEC_PER_DAY;
diff -= days * SEC_PER_DAY;
int hours = diff / SEC_PER_HOUR;
diff -= hours * SEC_PER_HOUR;
int minutes = diff / SEC_PER_MIN;
diff -= minutes * SEC_PER_MIN;
int seconds = diff;

NSLog(@"%d d, %d h, %d m and %d s.", days, hours, minutes, seconds);
于 2012-04-28T18:07:23.673 回答