Get UTC Date To Local Date in swift iOS -
i trying convert utc date local date in swift after utc local date in string convert string again in nsdate getting in utc date format, below code
date : in utc : 2016-07-20 18:30:00 +0000
i trying date in local date, check below code:
let dateinutc = nsdate() let seconds: int = nstimezone.systemtimezone().secondsfromgmt print(seconds) let localdateformatter: nsdateformatter = nsdateformatter() localdateformatter.dateformat = "mm/dd/yyyy hh:mm" localdateformatter.timezone = nstimezone(forsecondsfromgmt: seconds) let lastdate: string = localdateformatter.stringfromdate(dateinutc) print(lastdate)
at time getting “07/12/2016 16:56:36 gmt+5:30”, means got local date in string want date in nsdate again convert string date in nsdate,check below
let getdate:nsdate = localdateformatter.datefromstring(lastdate)! print(getdate)
but @ stage again got date in utc (2016-07-12 11:26:36 +0000) want in local date,
- i tried lot of times in swift not getting local date string,this line of code used in objective-c, working fine in obj-c when trying in swift utc date,suggest me , give me right way sol this.
nsdates don't save time zone information. have use dateformatter time zone when retrieving.
Comments
Post a Comment