如何在java的SimpleDateFormat中避免单引号 [英] How to escape single quote in java's SimpleDateFormat
本文介绍了如何在java的SimpleDateFormat中避免单引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
{ts'2012-08-13 02:30:01'}
我相信我可以使用单引号将无效部分转义,但在无效部分中有单引号。我该怎么逃避呢?我尝试了几种模式,但它不起作用。
谢谢,
解决方案>
可以使用单引号(')引用文本,以避免解释。
代表单引号。
所以一个格式字符串,如:
'{ts'''yyyy-MM-dd HH:mm:ss' '''''
应该匹配 {ts'2012-08-13 02:30:01'}
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,
解决方案
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'}
这篇关于如何在java的SimpleDateFormat中避免单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文