Question

I would like to have date formatted like here on SO: "Feb 6, '14".

I cannot put the apostrophe there before the number 14.

I tried the following formatter strings:

{{model.since | date:'MMM d, \'yy'}}
{{model.since | date:'MMM d, 'yy'}}
{{model.since | date:"MMM d, 'yy"}}
{{model.since | date:"MMM d, 'yy"}}

The apostrophe is not displayed.

How can I put the apostrophe there?

Was it helpful?

Solution

From the documentation on date:

In order to output single quote, use two single quotes in a sequence (e.g. "h 'o''clock'").

Since a string literal must also be enclosed in single quotes, you need four single quotes in a row. And since you're using single quotes in your format, you need to enclose the entire format string with double quotes, rather than single quotes.

Thus, your formatter string should be {{model.since | date:"MMM d, ''''yy"}}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top