毫秒转换成秒 ios?ios 隔多久后的时间?NSTimeInterval的使用

电脑杂谈  发布时间:2016-06-10 20:02:22  来源:网络整理

你是否正在寻找关于nstimeinterval的内容?让我把最权威的东西奉献给你:

nstimeinterval_毫秒转换成秒 ios_ios 隔多久后的时间

第一种方式:
nstimeinterval time = ...;
NSString *string = [NSString stringWithFormat:@"%02li:%02li:%02li",
lround(floor(time / 3600.)) % 100,
lround(floor(time / 60.)) % 60,
lround(floor(time.)) % 60];

第二种方式:
// You could also have stored the start time using
// CFAbsoluteTimeGetCurrent()
nstimeinterval elapsedTime = [startDate timeIntervalSinceNow];

// Divide the interval by 3600 and keep the quotient and remainder
div_t h = div(elapsedTime, 3600);
int hours = h.quot;
// Divide the remainder by 60; the quotient is minutes, the remainder
// is seconds.
div_t m = div(h.rem, 60);
int minutes = m.quot;
int seconds = m.rem;

// If you want to get the individual digits of the units, use div again
// with a divisor of 10.

NSLog(@"%d:%d:%d", hours, minutes, seconds)

如果您有您初始日期存储在 NSDate 对象时,您可以获得新日期任何时间间隔在未来,。只需使用 dateByAddingTimeInterval: 像这样:

NSDate * originalDate = [NSDate date];
nstimeinterval interval = 1;
NSDate * futureDate = [originalDate dateByAddingTimeInterval:interval];

ios获取自1970年以来的毫秒数同java的System.currentTimeMillis()

+ (NSString*)generateTimeIntervalWithTimeZone { NSMutableString *result = [[NSMutableString alloc] init]; NSDate *date = [NSDate date]; NSTimeInterval time = [date timeIntervalSince1970]*1000;//毫秒数要乘以1000 double i=time; //nstimeinterval返回的是double类型 NSDateFormatter *format = [[NSDateFormatter alloc] init]; [format setDateFormat:@"Z"]; NSString *timeZone = [format stringFromDate:date]; NSString *timeIntervalStr = [NSString stringWithFormat:@"%.f", i]; [result appendString:timeIntervalStr]; [result appendString:timeZone]; return result; }

以上就是关于nstimeinterval的全部内容,相信你一定会非常满意。


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/ruanjian/article-8546-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      • 太祖完颜阿骨打
        太祖完颜阿骨打

        也就是看是否属于无害通过

      • 渡洋史
        渡洋史

        我TMD也是醉了

      • 神木隆之介
        神木隆之介

        中国应该实行

      热点图片
      拼命载入中...