0

I saved a date in a sqlite database. Know I try to get the hours and the minutes. But the hours are shifted by 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)")
                }

            }

I get the following output:

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

The timezone is correct. I tryed two other solutions. But it is always the same problem.

SamuelTJackson
  • 1,357
  • 3
  • 19
  • 40
  • 1
    There is no problem, the output is correct. `print(someDate)` prints in UTC, and the date components are in your local timezone. – Martin R Aug 19 '16 at 07:50

1 Answers1

1

The result.dateForColumn("time") is in UTC since you have +0000 whereas the second output is in another timezone (Europe/Berlin (GMT+2)), so the date is the same.

Marco Santarossa
  • 4,058
  • 1
  • 29
  • 49