ios - DateFormatter producing unexpected result on device -
this question has answer here:
- nsdateformatter show wrong year 1 answer
i have following code:
var components = datecomponents() components.year = 2017 components.month = 1 var calendar = calendar.current let date = calendar.date(from: components)! let formatter = dateformatter() formatter.setlocalizeddateformatfromtemplate("mmmmyyyy") let string = formatter.string(from: date)
when run in simulator on computer works expect , value of string
january 2017.
however, when run same code on device value of string
january 2016. can causing difference?
the difference
- a different locale on device , simulator.
and / or
yyyy
year in week of year based calendar.yyyy
year in standard calendar.
you should use yyyy
.
Comments
Post a Comment