首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSGregorianCalendar到NSCalendar

NSGregorianCalendar到NSCalendar
EN

Stack Overflow用户
提问于 2011-07-27 21:24:48
回答 1查看 978关注 0票数 0

我正在寻找一种可以将NSGregorianCalendar转换为时间戳的技术/方法。我可以做一个双精度时间戳,但不能做整数时间戳

下面是我的代码:

代码语言:javascript
复制
//Create the timestamp of the date
NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
// NSTimeInterval is defined as double
NSNumber *timeStampObj = [NSNumber numberWithDouble: timeStamp];
NSLog(@"%@", timeStampObj);

但是它给了我一个1311780128.540395类型的时间戳,我只想要1311780128

感谢你帮我

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-27 23:30:43

如果您只想要整数部分,则将双精度数转换为int:

代码语言:javascript
复制
NSNumber *timeStampObj = [NSNumber numberWithInt: (int)timeStamp];
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6845055

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档