`

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;

    }  

分享到:
评论
2 楼 gdpglc 2015-09-17  
222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
1 楼 gdpglc 2012-10-31  
  public static String getTime_0(){ 
       return new SimpleDateFormat("M/dd/yyyy").format(new Date());
  } 

相关推荐

Global site tag (gtag.js) - Google Analytics