ITeye博客

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

treblesoftware · 2012-02-15 21:47 · 编程语言 · 编程语言 · Markdown

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)

  1. #2 楼 · gdpglc · 2015-09-17 09:09

    222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222

  2. #1 楼 · gdpglc · 2012-10-31 08:47

    public static String getTime_0(){
    return new SimpleDateFormat("M/dd/yyyy").format(new Date()); }

评论功能维护中,当前仅展示历史评论。