java 如何在 SimpleDateFormat 中插入特殊字符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2912149/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I insert special characters in SimpleDateFormat?
提问by Mahmoud Saleh
I want to insert the word 'at' in a SimpleDateFormatso a date would look like:
我想在 a 中插入“at”这个词,SimpleDateFormat所以日期看起来像:
Wed, 26 May 2010 at 11:17am
2010 年 5 月 26 日,星期三,上午 11:17
I'm able to make it appear without the at, like this
我可以让它在没有 at 的情况下出现,就像这样
Wed, 26 May 2010 11:17am
2010 年 5 月 26 日星期三上午 11:17
by using
通过使用
SimpleDateFormat formatter = new SimpleDateFormat("EEE, d MMM yyyy hh:mma");
How can I insert the word "at"?
如何插入单词“at”?
回答by Mattias
You can escape literals using single quotes.
您可以使用单引号转义文字。
SimpleDateFormat formatter = new SimpleDateFormat("EEE, d MMM yyyy 'at' hh:mma");
This will output Wed, 26 May 2010 at 11:17am
这将输出 2010 年 5 月 26 日星期三上午 11:17

