将毫秒转换为NSDate [英] Convert milliseconds to NSDate

查看:130
本文介绍了将毫秒转换为NSDate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个1273636800000,我想把它转换成这种格式Wed Mar 03 2010 00:00:00 GMT-0500(EST)

I have this "1273636800000" and I want to convert it to this format "Wed Mar 03 2010 00:00:00 GMT-0500 (EST)"

我需要将这个毫秒转换为NSDate格式。

I need to convert this milliseconds to NSDate format.

我试过这个

NSDate * tr = [NSDate dateWithTimeIntervalSince1970:1273636800000];

NSDate * tr = [NSDate dateWithTimeIntervalSinceReferenceDate:1273636800000];

NSDate * tr = [NSDate dateWithTimeIntervalSinceNow:1273636800000];

但我无法得到它工作,任何人有类似的问题,并找到解决方案

But I can't get it to work, anyone had a similar problem and found the solution

推荐答案

这些函数(dateWithTimeIntervalSince1970,dateWithTimeIntervalSinceReferenceDate,dateWithTimeIntervalSinceNow)以秒为单位接受参数。

These functions (dateWithTimeIntervalSince1970, dateWithTimeIntervalSinceReferenceDate, dateWithTimeIntervalSinceNow) accept parameter in seconds.

NSDate *date = [NSDate dateWithTimeIntervalSince1970:(ms / 1000.0)];

您应该通过1273636800.000

You should pass 1273636800.000

NSDate *date = [NSDate dateWithTimeIntervalSince1970:(1273636800 / 1000.0)];

这篇关于将毫秒转换为NSDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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