I want to insert a single quote character before year.
format(parseISO(date), "dd MMM '\''yy");
this does not seem to work. According to date-fns documentation, to add characters, we need to include them between two single quotes. I get the output for the above code as 06 Apr 'yy
whereas the expected output is 06 Apr '20
.
From the documentation:
Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote. (see the last example)
The last example shows how to do it:
// Escape string by single quote characters:
var result = format(new Date(2014, 6, 2, 15), "h 'o''clock'")
//=> "3 o'clock"
So in your case it should be:
format(parseISO(date), "dd MMM ''yy");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With