Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't put a single quote before the year in NSDateFormatter

I want to format my date as follows:

Mon, Apr 14 '09

The dateFormat I'm setting for my NSDateFormatter is EEE, MMM dd 'yy but it shows:

Mon, Apr 14 'yy

If I take out the single quote before the year, I get the last two digits of the year but it's not obvious that it's the year because the single quote is gone. Help?

I've also tried putting ''', '\'', and '\''' before 'yy' but it doesn't work, although the last two produced 'yy and ''09

like image 837
MLQ Avatar asked Apr 14 '14 11:04

MLQ


People also ask

How do I change the date format in swift5?

I solved my problem to the format yyyy-MM-dd'T'HH:mm:ss. SSS'Z' (e.g 2018-06-15T00:00:00.000Z) with this: func formatDate(date: String) -> String { let dateFormatterGet = DateFormatter() dateFormatterGet. dateFormat = "yyyy-MM-dd'T'HH:mm:ss.

What is DateFormatter in Swift?

A formatter that converts between dates and their textual representations.


1 Answers

From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns:

In patterns, two single quotes represents a literal single quote, …

In your case:

 [formatter setDateFormat:@"EEE, MMM dd ''yy"];
like image 90
Martin R Avatar answered Oct 16 '22 21:10

Martin R