Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Swift4 how to print short weekday only using DateFormatter()?

I want to have date formatter print only the short weekday label, like "Mon, Tue, Wed".

What is the correct date format to convert day into 3 letter weekday string?

let formatter = DateFormatter()
formatter.dateFormat = "DDD" //prints 278 and like
like image 535
Alex Stone Avatar asked Oct 07 '18 20:10

Alex Stone


2 Answers

It's like I have to learn this stuff every few months all over again:

let formatter = DateFormatter()
formatter.dateFormat = "EEE"


E..EEE  Tue Abbreviated Day of week name, format style.
EEEE    Tuesday Wide
EEEEE   T   Narrow
EEEEEE  Tu  Short
like image 178
Alex Stone Avatar answered Oct 17 '22 11:10

Alex Stone


Use this http://nsdateformatter.com

Monday, Oct 8, 2018 = EEEE, MMM d, yyyy

10/08/2018 = MM/dd/yyyy

10-08-2018 04:29 = MM-dd-yyyy HH:mm

Oct 8, 4:29 AM = MMM d, h:mm a

October 2018 = MMMM yyyy

Oct 8, 2018 = MMM d, yyyy

Mon, 8 Oct 2018 04:29:53 +0000 = E, d MMM yyyy HH:mm:ss Z

2018-10-08T04:29:53+0000 = yyyy-MM-dd'T'HH:mm:ssZ

08.10.18 = dd.MM.yy
like image 28
Sanket Ray Avatar answered Oct 17 '22 10:10

Sanket Ray