获取到当前系统的日期后,结果是5/9/2007
如何让结果变成05/09/2007  14:05呢???

解决方案 »

  1.   

    使用SimpleDateFormat,详查JavaDoc。
      

  2.   

    http://www.javaref.cn/egs/java.text/FormatTime.html
    A pattern of special characters is used to specify the format of the time. This example demonstrates some of the characters. For a complete listing, see the javadoc documentation for the SimpleDateFormat class. 
    Note: This example formats dates using the default locale (which, in the author's case, is Locale.ENGLISH). If the example is run in a different locale, the text (e.g., month names) will not be the same.     Format formatter;
        
        // The hour (1-12)
        formatter = new SimpleDateFormat("h");     // 8
        formatter = new SimpleDateFormat("hh");    // 08
        
        // The hour (0-23)
        formatter = new SimpleDateFormat("H");     // 8
        formatter = new SimpleDateFormat("HH");    // 08
        
        // The minutes
        formatter = new SimpleDateFormat("m");     // 7
        formatter = new SimpleDateFormat("mm");    // 07
        
        // The seconds
        formatter = new SimpleDateFormat("s");     // 3
        formatter = new SimpleDateFormat("ss");    // 03
        
        // The am/pm er
        formatter = new SimpleDateFormat("a");     // AM
        
        // The time zone
        formatter = new SimpleDateFormat("z");     // PST
        formatter = new SimpleDateFormat("zzzz");  // Pacific Standard Time
        formatter = new SimpleDateFormat("Z");     // -0800
        
        // Get today's date
        Date date = new Date();
        
        // Some examples
        formatter = new SimpleDateFormat("hh:mm:ss a");
        String s = formatter.format(date);
        // 01:12:53 AM
        
        formatter = new SimpleDateFormat("HH.mm.ss");
        s = formatter.format(date);
        // 14.36.33参考:http://www.javaref.cn/egs/java.text/pkg.html
      

  3.   

    用simpledateformat 格式化。。
      

  4.   

    Date now = new Date();
    DateFormat df = new SimpleDateFormat("MM/dd/yyyy  HH:mm");  
                    
    System.out.println("At the tone, the time is " + df.format(now));
      

  5.   

     回复人:joejoe1991() ( 一级(初级)) 信誉:100  2007-05-29 14:14:46  得分:0

    用simpledateformat 格式化。。
    Top
    回复人:wuheng66888(吴恒) ( 二级(初级)) 信誉:100  2007-05-29 14:16:19  得分:0

    Date now = new Date();
    DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm");System.out.println("At the tone, the time is " + df.format(now));--------
    同意
      

  6.   

    如果是字符串:)
    String str ="5/9/2007";
    System.out.println(str.replaceAll("\\d/", "0$0"));
      

  7.   

    是在两个文本框中显示的...
    <input name="starttime" type="text" value=<%=month+"/"+day+"/"+year+"----"+hour+":"+minute%> maxlength="50" readonly="true">
      

  8.   

    你看我这样写可以吗...为什么还是显示不出来呢.例5月..显示05月 
       <%!   
              Calendar   cal   =   Calendar.getInstance();   
      int   year   =   cal.get(Calendar.YEAR);   
      int   month   =   cal.get(Calendar.MONTH)+1; //正常显示的月  
      int   day   =   cal.get(Calendar.DATE); //正常显示的日
      int   hour=    cal.get(Calendar.HOUR_OF_DAY);
      int   minute   =   cal.get(Calendar.MINUTE);
      int   mon   =   cal.get(Calendar.MONTH)+1;//月
      int   daya   =   cal.get(Calendar.DATE);//日
      int   dayadd=7;//加的7天
      int   date=daya+dayadd;//判断是否大于31
      String monn=null,da=null;    %>
       <%
    if(month<10 && day<10){
      monn="0"+String.valueOf(month);
      da="0"+String.valueOf(day);
       %>
        <input name="starttime" type="text" value=<%=monn+"/"+da+"/"+year+"----"+hour+":"+minute%> maxlength="50" readonly="true">
        <%}%>
      

  9.   

    用Calendar自定义日期后
    再用simpledateformat格式化就可以了啊 不用那么麻烦去自己写日期的格式
      

  10.   

    哦..我去试试...
    joejoe1991() 这位.如何能联系到你呢...QQ.MSN.Skype..
      

  11.   

    QQ1924627 QQ不怎么上的。我也是新手哈。