简体   繁体   中英

NSDate as function parameter in Swift

I'm facing an issue if I pass NSDate as a function parameter.

My code is:

self.PassDate(responseDate) ; // Response date value = 2015-05-15T00:00:00

func PassDate(date:NSDate) {

      // Here ideally date value should be same as responseDate value.. but date is coming as 2015-05-14T07:00:00 PDT
}

Why passing NSDate is changing the timezone/values?

Nothing is changing. Different ways of viewing dates present them using different time zones. The underlying date is not changed. If you view the date in the debugger it (usually) shows it in UTC.

Try logging the date outside your function and inside using println() calls. You should see the same value in both places if you view it the same way each time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM