首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

JAVA日期格式输出月度前面不想被自动补0

2012-08-29 
JAVA日期格式输出月份前面不想被自动补0JAVA日期格式输出月份前面不想被自动补0,那么就用SimpleDateFormat

JAVA日期格式输出月份前面不想被自动补0

JAVA日期格式输出月份前面不想被自动补0,那么就用SimpleDateFormat("M/dd/yyyy");,一个M。

如果想被自动补0,那么就用MM。SimpleDateFormat("MM/dd/yyyy");

?

? /**?

? ? ?* 返回 2/15/2012 格式的STRING类型,用M月份不会自动补0.用MM,月份会自动补0

? ? ?*/ ?

? ? public static String getTime_0(){ ?

? ? ? ? //此处字符串的格式可以修改 ?

? ? ? ? SimpleDateFormat formatter = new SimpleDateFormat("M/dd/yyyy"); ?

? ? ? ? Date currentTime = new Date();//得到当前系统时间 ?

? ? ? ? String timeStr = formatter.format(currentTime); //将日期时间格式化 ??

? ? ? ?// System.out.println("[1] " + timeStr); ? ??

? ? ? ? //输出:[1] ? ?2009-08-18 20:06:13 ?

? ? ? ? return timeStr;

? ? } ?

热点排行