nsdate - swift stored date turns different when formatted to string -
this question has answer here:
- nsdate format outputting wrong date 5 answers
i stored date in core data (as date), , println shows correctly value: april 21 (is var datex below), when right after println format string following code, label linked shows april 22 (which today, wonder tomorrow show 23 etc.), problem? anyone? thank you
if datex != nil{ var dateformatter = nsdateformatter() dateformatter.dateformat = "mmm dd, yyyy" dateformatter.timezone = nstimezone.defaulttimezone() var datexstring = dateformatter.stringfromdate(datex nsdate) startlabel.text = "profile created on \(datexstring)" }
println datex , datexstring:
my time zone rome (italy)
you have timezone issue. located? defaulttimezone
gmt/zulu time -5 hrs east coast.
a way check use timeintervalsince1970
function (i think thats called). if stored date , retrieved date have same value same date , have display problem.
timeintervalsince1970
returns nstimeinterval
double
Comments
Post a Comment