Iphone 存储时间戳值并将其显示给UI

Iphone 存储时间戳值并将其显示给UI,iphone,timestamp,storage,Iphone,Timestamp,Storage,在我的应用程序中,我使用JSON获得如下时间戳值: 2010-07-05 11:10:16.0 CEST的1278321016000 1278436867000用于2010-07-06 19:21:07.0 CEST 我目前正在将此值存储为long类型,但我想知道这是否是正确的方法,我是否必须使用NSTimeInterval搜索内容 存储此值后,在UILabel对象中显示此值的最佳方式是什么,看起来像“YYYY-MM-DD hh:MM:ss” 我尝试使用NSDate对象,但无法获取initW

在我的应用程序中,我使用JSON获得如下时间戳值:

  • 2010-07-05 11:10:16.0 CEST的1278321016000
  • 1278436867000用于2010-07-06 19:21:07.0 CEST
我目前正在将此值存储为long类型,但我想知道这是否是正确的方法,我是否必须使用NSTimeInterval搜索内容

存储此值后,在UILabel对象中显示此值的最佳方式是什么,看起来像“YYYY-MM-DD hh:MM:ss”

我尝试使用NSDate对象,但无法获取initWithTimeIntervalSince1970方法


提前谢谢你

请注意,NSTimeInterval使用秒,而不是毫秒。下面是一些创建日期并显示日期的代码。我还没有把它放进XCode并运行它,所以请原谅任何错误

// convert to a usable time interval
NSTimeInterval timeInterval = 1278321016;

// convert the time interval to a date
NSDate *myDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];

// create the formatter for the desired output
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

// set the label text
myLabel.text = [formatter stringFromDate:myDate];

// cleanup
[formatter release];

感谢您的回答,什么是时间间隔值类型?我想把我得到的值除以1000,但我有一个奇怪的值。。。肯定是类型错误。您是将除法结果指定给NSTime Interval还是在NSTime Interval上除法?NSTimeInterval:现在很好!我必须像这样初始化timeInterval:NSTimeInterval timeInterval=[myData unsignedLongLongValue]/1000;谢谢你的帮助!