调用stringWithFormat时长时间使用哪个正确的说明符? [英] which is the correct specifier to use for long when calling stringWithFormat?

查看:57
本文介绍了调用stringWithFormat时长时间使用哪个正确的说明符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码可以很好地工作,但是我不知道这是否是调用stringWithFormat的正确方法,因为在文档%d中,int是用于int的,并且我要传递很长的一段代码:

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];

提前谢谢!

推荐答案

尝试%ld :

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

来自 printf docs的摘要(NSString的stringWithFormat格式遵循相同的标准作为printf函数):

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

l(ell)
指定后续的d,i,o,u,x或X转换说明符适用于long或unsigned long参数

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

这篇关于调用stringWithFormat时长时间使用哪个正确的说明符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆