Home >Web Front-end >HTML Tutorial >swift_There is a problem of several hours difference when transferring the time obtained by UIDatePicker to the next page_html/css_WEB-ITnose

swift_There is a problem of several hours difference when transferring the time obtained by UIDatePicker to the next page_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:57:401295browse

Today, I encountered a very strange problem when writing a swift demo. I used UIDatePicker to select the time on the presented page, and then transferred the obtained time back to the original main interface. The result was a problem Appears: The acquisition time of page B is normal, but the time after page A is returned is 9 hours less. I was puzzled, so I found some answers on Google and said it was like this:

 time.timeZone = NSTimeZone.systemTimeZone() time.calendar = NSCalendar(calendarIdentifier: NSGregorianCalendar)
Even after adding it, it had no effect, and the difference was still the same 9 hours. Later, I found another solution like this:

let timeZone = NSTimeZone.systemTimeZone()let seconds = timeZone.secondsFromGMTForDate(addObject.time.date)let correctDate = addObject.time.date.dateByAddingTimeInterval(Double(seconds))

Although the problem was solved, I still don’t understand why. Could this be the reason for the XCode GM version (unlikely~). I hope those who know the reason will give me some advice and we can make progress together!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn