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

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -