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
295 views
in Technique[技术] by (71.8m points)

iphone - NSDate not returning correct date

I am printing NSDate like this:

NSDate *date = [NSDate date];
NSString *stringDate = [data description];

Right now, it's July 1, 2011 11:43 pm. My iPod even says that on the top bar. But stringDate prints out: 2011-07-02 03:43:46 +0000

This is obviously wrong. I have used NSDate millions of times but never had this problem. What could be wrong? Thanks

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Your region's time offset is -04:00? NSDate will automatically adjust the time offset when displaying the date. Try,

NSString *str = [date descriptionWithLocale:[NSLocale currentLocale]];

It will show you the correct date.


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

...