Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
561 views
in Technique[技术] by (71.8m points)

objective c - Convert milliseconds to NSDate

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

I need to convert this milliseconds to NSDate format.

I tried this

NSDate *tr = [NSDate dateWithTimeIntervalSince1970:1273636800000];

and

NSDate *tr = [NSDate dateWithTimeIntervalSinceReferenceDate:1273636800000];

and

NSDate *tr = [NSDate dateWithTimeIntervalSinceNow:1273636800000];

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

You should pass 1273636800.000

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...