2012-11-24 6 views
-1

가능한 중복 : NSDate 문제 .. 잘못된 시간?

I 그래서 같이 현재 시각을 표시하려고
NSDate not returning correct date

: MyDate가있는 NSDate * = [있는 NSDate 일]; 시뮬레이터 시간 및 OS X 시간이 다르지만 이시간에 의해

2012-11-24 09:27:13.194 myApp[5284:c07] mydate = 2012-11-24 07:27:13 +0000 

시간 오프 :

나는이 결과를 얻는다. 어떻게 해결할 수 있습니까? 미리 감사드립니다.

+1

확인이 답변 : HTTP :의 //stackoverflow.com/a/3413414/1548523 – sunkehappy

+1

중복 : http://stackoverflow.com/q/6741519/927947 & http://stackoverflow.com/q/6554999/927947 – NJones

답변

2

NSDateFormatter로 날짜를 출력해야합니다. NSDate에는 시간대 정보가 첨부되지 않습니다. 날짜 포맷터에 시간대를 연결하십시오.

NSDate* now = [NSDate date]; 

// GET A DATE FORMATTER AND SET THE TIMEZONE 
NSDateFormatter *df = [[NSDateFormatter alloc] init]; 
df.timeZone = [NSTimeZone systemTimeZone]; 

// CHANGE FORMAT TO SUIT YOUR NEEDS 
[df setDateStyle: NSDateFormatterFullStyle]; 
[df setTimeStyle: NSDateFormatterFullStyle]; 

// GET YOUR FORMATTED DATE STRING 
NSString *dateString = [df stringFromDate: now];