Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get every name of month components in swift

I want to get an array of months from Calendar component in swift. Like:

var monthComponents = ["Jan", "Feb", "Mar" ..]

But I'm only able to get whether the current date or convert a certain date format to string. So, how could I get all month components (month names). Please suggest me with a simple way.

like image 337
Aashish Avatar asked Dec 14 '16 04:12

Aashish


1 Answers

The DateFormatter class has what you need:

let formatter = DateFormatter()
let monthComponents = formatter.shortMonthSymbols

See the docs for DateFormatter to see all of the other related methods for getting other various symbols.

Or as of iOS 10/macOS 10.12 you can use Calendar:

let monthComponents = Calendar.current.shortMonthSymbols
like image 135
rmaddy Avatar answered Nov 15 '22 07:11

rmaddy