NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@\"dd-MM-YYYY HH:mm\"];
[formatter setTimeZone:[NSTimeZone syst
for swift 4 go with:
if let dateFormatter = DateFormatter(){
dateFormatter.dateStyle = .medium
// eventually:
//let locale = Locale(identifier: ...
//dateFormatter!.locale = locale
dateFormatter.dateStyle = .medium
dateFormatter!.dateFormat = "dd MMM YYYY, HH:mm:ss"
} else..
..
Actually you can set your dateStyle to medium (ie 'Jan', 'Feb' etc) like this:
[formatter setDateStyle:NSDateFormatterMediumStyle];
Have you tried: [formatter setDateFormat:@"dd-MMM-YYYY HH:mm"];
and then [formatter stringFromDate:someNSDate];
In SWIFT
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd MMM yyyy HH:mm"
dateFormatter.stringFromDate(NSDate())
IF you get the two things in the wrong order, you don't get the expected output.
[formatter setDateFormat:@"MMM"];
[formatter setDateStyle:NSDateFormatterMediumStyle];
does NOT give the same results as:
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setDateFormat:@"MMM"];
(The second of these two snippets is now happily handing out Sep Oct etc in my app)
For those who do not get a full month strong with "MMM", you can get it with
dateFormatter.dateFormat = "dd MMMM yyyy"
Tested on Swift 4.2