Do Not Think!!!

최근 사진

2011/12 시즌 2012년 2월 18-19일 용평리조트
2011/12 시즌 2012년 1월 27-28일 휘닉스파크
사무실 이사
2011/12시즌 2011년 12월 17일 휘닉스파크
2011/12시즌 2011년 12월 10일 휘닉스파크
2011/12시즌 2011년 12월 4일 휘닉스파크
2011/12시즌 2011년 11월 26일 휘닉스파크
2011년 8월 뉴질랜드 여행
2011년 5월 4일 ~ 7일 홍콩 워크샵 사람
2011년 5월 4일 ~ 7일 홍콩 워크샵 넷 째날

최근 트랙백

Total226674
Today3
Yesterday103

NSDate 와 코어데이터의 Dates and Times

NSDate
The sole primitive method of NSDate, timeIntervalSinceReferenceDate, provides the basis for all the other methods in the NSDate interface. This method returns a time value relative to an absolute reference date—the first instant of 1 January 2001, GMT.


Core Data Dates and Times
NSManagedObject represents date attributes using NSDate objects, and stores times internally as an NSTimeInterval
 value since the reference date (which has a time zone of GMT). Time 
zones are not explicitly stored—indeed you should always represent a 
Core Data date attribute in GMT, this way searches are normalized in the
 database. If you need to preserve the time zone information, you need 
to store a time zone attribute in your model. This may again require you
 to create a subclass of NSManagedObject.



Core Data 에 NSDate 를 저장하면,

2001-01-01 00:00:00 을 기준으로 한 time interval (double) 이 저장됩니다.
이 때, 기준이 되는 타임존은 Local TimeZone -> GMT 입니다.

예를 들면
한국에서 2011-11-25 11:21:02 라는 시간을 Core Data 에 저장하면
한국의 타임존 2011-11-25 11:21:02 +0900 이 아니라
GMT 2011-11-25 02:21:02 +0000 라는 시간이
1970-01-01 00:00:00 을 기준으로 한 time interval 1322187662 이 아니라, (timeIntervalSince1970)
2001-01-01 00:00:00 을 기준으로 한 time interval 343880462 가 저장됩니다. (timeIntervalSinceReferenceDate)

Core Data 에서 불러오면

2001-01-01 00:00:00 을 기준으로 한 time interval 으로 NSDate 객체를 만듦니다.
이 때, 기준이 되는 타임존은 GMT -> Local TimeZone 입니다.

예를 들면
저장된 343880462 을 한국에서 불러오면,
GMT 2011-11-25 02:21:02 +0000 라는 시간이 안니라,
한국의 타임존 2011-11-25 11:21:02 +0900 라는 시간이 만들어집니다.

하지만, 저장된 343880462 을 홍콩에서 불러오면
홍콩의 타임존 2011-11-25 10:21:02 +0800 라는 시간이 만들어집니다.


타임존을 이동하는 경우,

작성된 시간을 보여주기 위해서는
해당 타임존을 별도로 저장하고, 저장된 타임존을 이용해서 시간을 표시해야 합니다.

크리에이티브 커먼즈 라이센스
Creative Commons License

Trackback Address :: http://dont.pe.kr/tt/trackback/390

Name

Password

Homepage

Secret

PREV 1 ... 12 13 14 15 16 17 18 19 20 ... 360 NEXT