I basically have this code right now and I am trying to format by having a new line in between but it doesn't give me a new line. Am I doing it correctly?
The point of calling -dateFormatFromTemplate:locale:options:
is to get back a format string that's properly formatted for the specified locale. That is, the method looks at the date components you specify and arranges them to suit the local custom, like "Jan 2 2019" in the US, but "2 Jan 2019" in Europe. I think it basically ignores any parts of the template that it doesn't recognize as a date component specifier. If it's moving the date components around, how would it know where to place the non-date parts that it doesn't know about?
If you don't care about different locales and just want a date that has a newline in it, then you can skip that method and just create the template string yourself:
formatString = @"EEEE \n hh:mm";
[dateFormatter setDateFormat:formatString];
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"%@", dateString);
The code above will log the current date with a newline between the weekday and the time, so -stringFromDate:
will happily use your format string and keep the newline.
If you do care about locales but still want the newline, you'll have to either create your own locale-specific date format strings, or call -dateFormatFromTemplate:locale:options:
and then insert the newline at the right spot in the result.