如何在SimpleDateFormat中插入特殊字符? [英] How can I insert special characters in SimpleDateFormat?
本文介绍了如何在SimpleDateFormat中插入特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 SimpleDateFormat
中插入单词'at',以便日期看起来像:
I want to insert the word 'at' in a SimpleDateFormat
so a date would look like:
2010年5月26日,星期三,上午11:17
Wed, 26 May 2010 at 11:17am
我可以使它不显示at,就像这样
I'm able to make it appear without the at, like this
2010年5月26日,星期三,上午11:17
Wed, 26 May 2010 11:17am
通过使用
SimpleDateFormat formatter = new SimpleDateFormat("EEE, d MMM yyyy hh:mma");
如何插入"at"一词?
How can I insert the word "at"?
推荐答案
您可以使用单引号将文字转义.
You can escape literals using single quotes.
SimpleDateFormat formatter = new SimpleDateFormat("EEE, d MMM yyyy 'at' hh:mma");
这将在2010年5月26日星期三上午11:17输出
This will output Wed, 26 May 2010 at 11:17am
这篇关于如何在SimpleDateFormat中插入特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文