2016-08-19 1 views
0

Ich speicherte ein Datum in einer SQLite-Datenbank. Ich weiß, ich versuche, die Stunden und Minuten zu bekommen. Aber die Stunden verschoben von 2.Erhalten Sie Stunden pro Minutevon NSDate

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)") 
       } 

      } 

ich folgende Ausgabe:

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 

Die Zeitzone ist richtig. Ich habe zwei andere Lösungen versucht. Aber es ist immer das gleiche Problem.

+1

Es gibt kein Problem, die Ausgabe ist korrekt. 'print (someDate)' wird in UTC gedruckt und die Datumskomponenten befinden sich in Ihrer lokalen Zeitzone. –

Antwort

1

Die result.dateForColumn("time") ist in UTC da Sie +0000 haben, während die zweite Ausgabe in einer anderen Zeitzone (Europe/Berlin (GMT+2)) ist, so dass das Datum ist das gleiche.

Verwandte Themen