ios - On hour is substracted when converting a String to NSDate -


this question has answer here:

this code :

let datestring = "2015-07-13t17:32:32.781z" let dateformatter = nsdateformatter() dateformatter.dateformat = "yyyy-mm-dd't'hh:mm:ss.sss'z'" var thedate = dateformatter.datefromstring(datestring)! println(thedate)  // 2015-07-13 16:32:32 +0000 

one hour substracted original date during process. why ?

@mipadi has explained problem, think should set time zone utc.

    let datestring = "2015-07-13t17:32:32.781z"     let dateformatter = nsdateformatter()     dateformatter.dateformat = "yyyy-mm-dd't'hh:mm:ss.sss'z'"     dateformatter.timezone = nstimezone(abbreviation: "utc")     var thedate = dateformatter.datefromstring(datestring)!     println(thedate) 

Comments