How to escape single quote in java's SimpleDateFormat

date, java, simpledateformat

Solution

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'}`

Problem

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,

Original source