我提取的messageMap.cr_time是年月日时分秒毫秒,具体一个就是2007-07-15 11:13:18.96这种
我想提取月日时分,用的velocity
#(set(messageMap.cr_time=$messageMap.setDateFormat("cr_time", "MM-dd HH:mm"))貌似不起作用啊
请教各位了....
不胜感激~~~

解决方案 »

  1.   


    Calendar c = Calendar.getInstance();
    c.set(year,month,date);
    System.out.println(c.get(Calendar.Year));
    System.out.println(c.get(Calendar.Month));
    System.out.println(c.get(Calendar.Date));
      

  2.   

    String PATTERN_YYYY_MM_DD = "yyyy/MM/dd";
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(PATTERN_YYYY_MM);
    String date = simpleDateFormat.format(new Date());
      

  3.   

    String PATTERN_YYYY_MM_DD_HH_MM = "yyyy/MM/dd HH:mm";
    SimpleDateFormat   simpleDateFormat   =   new   SimpleDateFormat(PATTERN_YYYY_MM_DD_HH_M); 
    String   date   =   simpleDateFormat.format(new   Date());
      

  4.   

    字符串可以变化
    yyyy/MM/dd HH:mm
    根据需要变化
      

  5.   

    在velocity里面好像不能这样用...
      

  6.   

    messageMap.cr_time这是个什么类型的?如果messageMap.cr_time是个String可以直接在vm中截取字符串
    #set($newTime = messageMap.cr_time.substring(5,15))如果messageMap.cr_time是个Date。需要生成一个SimpleDateFormat对象
    SimpleDateFormat sdf = new SimpleDateForm("MM-dd HH:ss");
    把sdf压入到Velocity中:
    如果是Web程序,使用request.setAttribute("sdf", sdf);
    如果是其他应用,使用velocityContext.put("sdf", sdf);
    在vm文件中使用
    #set($newTime = sdf.format(messageMap.cr_time))
      

  7.   

    两个vm漏了个$,更正一下:#set($newTime = $messageMap.cr_time.substring(5,15))#set($newTime = $sdf.format($messageMap.cr_time))