Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I escape characters in an Angular date pipe?

I have an Angular date variable today that I'm using the date pipe on, like so:

{{today | date:'LLLL d'}} 

February 13

However, I would like to make it appear like this:

13 days so far in February

When I try a naive approach to this, I get this result:

{{today | date:'d days so far in LLLL'}} 

13 13PM201818 18o fPMr in February

This is because, for instance d refers to the day.

How can I escape these characters in an Angular date pipe? I tried \d and such, but the result did not change with the added backslashes.

like image 925
Thunderforge Avatar asked Feb 13 '18 21:02

Thunderforge


People also ask

How do you escape special characters?

Escape CharactersUse the backslash character to escape a single character or symbol. Only the character immediately following the backslash is escaped. Note: If you use braces to escape an individual character within a word, the character is escaped, but the word is broken into three tokens.

How do you escape characters in a string?

\ is a special character within a string used for escaping. "\" does now work because it is escaping the second " . To get a literal \ you need to escape it using \ .

How do you escape ascii?

ASCII escape character The ASCII "escape" character (octal: \033 , hexadecimal: \x1B , or ^[ , or, in decimal, 27 ) is used in many output devices to start a series of characters called a control sequence or escape sequence.

Which Slash is the escape character?

? The backslash character ( \ ) is the escaping character. It can be used to denote an escaped character, a string, literal, or one of the set of supported special characters. Use a double backslash ( \\ ) to denote an escaped string literal.


2 Answers

How about this:

{{today | date:'d \'days so far in\' LLLL'}} 

Anything inside single quotes is ignored. Just don't forget to escape them.

like image 140
Daniel P Avatar answered Sep 23 '22 09:09

Daniel P


This works for me {{today | date:"d 'days so far in' LLLL"}}

like image 42
Carlos Fagiani Jr Avatar answered Sep 25 '22 09:09

Carlos Fagiani Jr