带有日期和月份的Java printf [英] Java printf with date and month

查看:131
本文介绍了带有日期和月份的Java printf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

System.out.printf("Time: %d-%d %02d:%02d"    +            
 calendar.get(Calendar.DAY_OF_MONTH),
 calendar.get(Calendar.MONTH),
 calendar.get(Calendar.HOUR_OF_DAY), 
 calendar.get(Calendar.MINUTE);

这是朋友给我看的代码,但是如何让日期以11月1日的格式显示?

That is the code a friend showed me, but how do I get the date to appear in a Format like November 1?

推荐答案

这是怎么做的:

DateFormat dateFormat = new SimpleDateFormat( "MMMMM d" );
Calendar calendar = new GregorianCalendar(); // The date you want to format
Date dateToFormat = calendar.getTime();
String formattedDate = dateFormat.format( dateToFormat );
System.out.println( formattedDate );

这篇关于带有日期和月份的Java printf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆