<%@page contentType="text/html; charset=GB2312" %>
<%@page import="java.text.*"%>
<%@page import="java.util.*"%>
<%String s = "2009-03-12 20:55:30";try{
SimpleDateFormat myFormat = new SimpleDateFormat("MM-dd");
out.print("<br>0:"+myFormat.format(myFormat.parse(s)));SimpleDateFormat myFormat1 = new SimpleDateFormat("mm-dd");
out.print("<br>1:"+myFormat1.format(myFormat1.parse(s)));SimpleDateFormat myFormat2 = new SimpleDateFormat("yyyy-MM-dd");
out.print("<br>2:"+myFormat2.format(myFormat2.parse(s)));}catch(ParseException e){out.print(e);}%>为什么 MM-dd 与 mm-dd 显示的结果不一样 而且还不是我要的结果  
我想要的是显示03-12

解决方案 »

  1.   

    java里面大写的MM表示月份小写的mm表示分钟
      

  2.   

    在格式化中MM表示月,mm表示秒。
    你要的03-12由其他人帮你解决啦。
      

  3.   

    字母  日期或时间元素  表示  示例  
    G    Era 标志符     Text  AD  
    y    年              Year  1996; 96  
    M    年中的月份      Month  July; Jul; 07  
    w    年中的周数      Number  27  
    W    月份中的周数    Number  2  
    D    年中的天数      Number  189  
    d    月份中的天数    Number  10  
    F    月份中的星期    Number  2  
    E    星期中的天数    Text  Tuesday; Tue  
    a    Am/pm 标记     Text  PM  
    H    一天中的小时数(0-23)     Number  0  
    k    一天中的小时数(1-24)     Number  24  
    K    am/pm 中的小时数(0-11)  Number  0  
    h    am/pm 中的小时数(1-12)  Number  12  
    m    小时中的分钟数             Number  30  
    s    分钟中的秒数               Number  55  
    S    毫秒数                     Number  978  
    z    时区                       General time zone  Pacific Standard Time; PST; GMT-08:00  
    Z    时区                       RFC 822 time zone  -0800  
      

  4.   

    帮你搞定啦 String s = "2009-03-12 20:12:12";
    try{
    SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    Date d = myFormat.parse(s);
    SimpleDateFormat myFormat1 = new SimpleDateFormat("MM-dd");
    System.out.println(myFormat1.format(d));
    }catch(ParseException e){System.out.print(e);}
      

  5.   

    wy__wangyu 现在问题是s的值有可能是String s = "2009-03-12 20:12:12";  也有可能为:String s = "2009-03-12"; 
    看来只有用截取来实现了....
      

  6.   

    大写的MM表示月份小写的mm表示分钟
      

  7.   


    恩,不过如果你还是想使用SimpleDateFormat ,可以对String s 进行if判断,这要看你的程序具体的设计了。
      

  8.   

    学习了!!!
    java中是区分大小写的 啊,所以楼主 应该小心!
      

  9.   

    取字串:s.substring(5,10)
    结果:03-12