2016-08-19 1 views
0

sqlite 데이터베이스에 날짜를 저장했습니다. 시간과 분을 얻으려고 노력하는 것을 아십시오.NSDate에서 몇 시간 만에

Europe/Berlin (GMT+2) offset 7200 (Daylight) 
2016-08-17 18:44:57 +0000 
the hour is 20 and minute is 44 
2016-08-18 18:44:57 +0000 
the hour is 20 and minute is 44 
2016-08-19 15:44:57 +0000 
the hour is 17 and minute is 44 
2016-08-18 16:44:57 +0000 
the hour is 18 and minute is 44 
2016-08-17 18:44:57 +0000 
the hour is 20 and minute is 44 
2016-08-18 18:44:57 +0000 
the hour is 20 and minute is 44 
2016-08-19 15:44:57 +0000 
the hour is 17 and minute is 44 
2016-08-18 16:44:57 +0000 
the hour is 18 and minute is 44 

시간대가 올바른지 :하지만 시간이 나는 다음과 같은 출력을 얻을 2.

print(calendar.timeZone) 
while result.next() { 
       var hour = 0 
       var minute = 0 
       let calendar = NSCalendar.currentCalendar() 
       if #available(iOS 8.0, *) { 
        calendar.getHour(&hour, minute: &minute, second: nil, nanosecond: nil, fromDate: result.dateForColumn("time")) 
        print(result.dateForColumn("time")) 
        print("the hour is \(hour) and minute is \(minute)") 
       } 

      } 

로 이동합니다. 나는 다른 두 가지 해결책을 시도했다. 하지만 항상 같은 문제입니다.

+1

문제가 없으며 출력이 정확합니다. 'print (someDate)'는 UTC로 인쇄하고 날짜 구성 요소는 현지 시간대에 있습니다. –

답변

1

+0000이므로 result.dateForColumn("time")UTC이며 두 번째 출력은 다른 시간대 (Europe/Berlin (GMT+2))에 있으므로 날짜는 동일합니다.