Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs date filter ignores apostrophe

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?

like image 535
user2635204 Avatar asked May 23 '26 13:05

user2635204


1 Answers

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"}}

like image 192
Dave Avatar answered May 26 '26 16:05

Dave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!