在MM中从MM / DD / YYYY到DD-MMM-YYYY [英] Going from MM/DD/YYYY to DD-MMM-YYYY in java
本文介绍了在MM中从MM / DD / YYYY到DD-MMM-YYYY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是否有一种Java方法可以将 MM / DD / YYYY
转换为 DD-MMM-YYYY
?
Is there a method in Java that I can use to convert MM/DD/YYYY
to DD-MMM-YYYY
?
例如: 05/01/1999
到 01-MAY- 99
谢谢!
推荐答案
使用SimpleDateFormat解析日期,然后使用所需格式的SimpleDateFormat将其打印出来。
Use a SimpleDateFormat to parse the date and then print it out with a SimpleDateFormat withe the desired format.
以下是一些代码:
SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat format2 = new SimpleDateFormat("dd-MMM-yy");
Date date = format1.parse("05/01/1999");
System.out.println(format2.format(date));
输出:
01-May-99
这篇关于在MM中从MM / DD / YYYY到DD-MMM-YYYY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文