ios - DateFormatter producing unexpected result on device -


this question has answer here:

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

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -