Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 passing a long:

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

Thanks in advance!

like image 841
Javier Avatar asked Oct 03 '11 20:10

Javier


1 Answers

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

like image 132
Vladimir Avatar answered Nov 09 '22 23:11

Vladimir