将 epochTime 转换为 NSDate
我需要将纪元时间值转换为 NSDate.. 例如,我有这个纪元值(长):81915536 我对纪元值的时间值很感兴趣。
我已经尝试过:
NSDate* date = [NSDate dateWithTimeIntervalSince1970:81915536];
但我得到了 70 年代的约会......这是错误的。
但是在Java中,当我使用这段代码时,我获得了正确的时间值。
Date time = new Date(Long.valueOf(_epochTime));
String minutes = time.getMinutes()+"";
if(minutes.length()==1)
minutes="0"+minutes;
return time.getHours()+":"+minutes;
有人可以帮我解决这个问题吗?
I need to convert an epoch time value to NSDate..
For exemple I have this epoch value (long) : 81915536
I'm interesting by the time value of the epoch value.
I have try that :
NSDate* date = [NSDate dateWithTimeIntervalSince1970:81915536];
but I got a 70's date....It's wrong.
But in a Java when I use this code, I obtain the right time value.
Date time = new Date(Long.valueOf(_epochTime));
String minutes = time.getMinutes()+"";
if(minutes.length()==1)
minutes="0"+minutes;
return time.getHours()+":"+minutes;
Someone can help me with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当前的 UNIX 时间是 1310407007,您给出的秒数实际上是七十年代,请参见此处:http://www.unixtimestamp.com/index.php unixtimestamp.com/index.php。
另外,您似乎没有检查 Java 代码中的年份,而只检查了小时和分钟。
还有一件事,如果您希望将常量视为 long 而不是 int,请添加后缀
L
:81915536L
The current UNIX time is 1310407007 the seconds you gave are actually in the seventies, see here: http://www.unixtimestamp.com/index.php.
Also, it doesn't seem that you check the year in your Java code, only the hours and minutes.
One more thing, if you want a constant to be treated as long and not as int, add a postfix of
L
:81915536L