Which is the right qualifier for long use when calling stringWithFormat?

I have this code that works well, but I don’t know if this is the correct way to call stringWithFormat, because in the documentation% d for int and I pass long:

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

Thanks in advance!

+4
source share
1 answer

Try %ld :

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

Printf docs annotation (NSString stringWithFormat format follows the same standard as the printf function):

l (ell)
Indicates that the following transformations of d, i, o, u, x, or X specifier apply to a long or unsigned long argument

+5
source

All Articles