I have a date input date like this: {ts '2012-08-13 02:30:01'}
I believe I can escape the invalid part with single quotes, but I have a single quote within the invalid part. How do I escape that? I tried a couple of patterns but it is not working.
Thanks,
Single quotes need to be escaped by backslash in single-quoted strings, and double quotes in double-quoted strings.
It's done by finishing already opened one ( ' ), placing escaped one ( \' ), then opening another one ( ' ). This syntax works for all commands.
Use escapeEcmaScript method from Apache Commons Lang package: Escapes any values it finds into their EcmaScript String form. Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.). So a tab becomes the characters '\\' and 't' .
This is what worked for me
SimpleDateFormat("dd MMM''yy", Locale.ENGLISH)
01 Jan'20
According to the javadocs for SimpleDateFormat
Text can be quoted using single quotes (') to avoid interpretation.
"''"
represents a single quote.
So a format string like:
"'{ts '''yyyy-MM-dd HH:mm:ss'''}'"
should match {ts '2012-08-13 02:30:01'}
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