开发者

which is the correct specifier to use for long when calling stringWithFormat?

开发者 https://www.devze.com 2023-04-10 02:57 出处:网络
I have this code which works well but I don\'t know if it is the correct way to call stringWithFormat because in the documentation %d is for int and I\'m pass开发者_Go百科ing a long:

I have this code which works well but I don't know if it is the correct way to call stringWithFormat because in the documentation %d is for int and I'm pass开发者_Go百科ing a long:

    long seconds = (long)[[NSDate date]timeIntervalSince1970];
    NSString *unixTimestamp = [NSString stringWithFormat:@"date=%d", seconds];

Thanks in advance!


Try %ld:

 NSString *unixTimestamp = [NSString stringWithFormat:@"date=%ld", seconds];

Abstract from printf docs (NSString's stringWithFormat format follows the same standard as printf function):

l (ell)
Specifies that a following d, i, o, u, x, or X conversion specifier applies to a long or unsigned long argument

0

精彩评论

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

关注公众号