我有两个linux时间戳开始时间和到期时间,我想在几小时,分钟之间区分这两个时间戳。
语言:目标C
“expire_time”:“1366927200”,“begin_time”:“1327532400”,
答案 0 :(得分:-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);