.dateToStr(new Date(), Locale.CHINA));  调用------------------------------ public static Date convertStrToDate(String strDate, Locale locale) {
if (strDate == null) {
return null;
}

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", locale);
TimeZone zone = TimeZone.getDefault();
formatter.setTimeZone(zone);
Date formatDate = null;
try {
formatDate = formatter.parse(strDate);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(formatDate); return formatDate;
} public static void main(String[] args) {
convertStrToDate("2002-12-12", Locale.CHINESE);
} public static String dateToStr(Date date, Locale locale) {
if (date == null) {
return null;
}
if (locale == null) {
locale = Locale.getDefault();
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm",
locale);
TimeZone zone = TimeZone.getDefault();
formatter.setTimeZone(zone);
return formatter.format(date);
}
----------------------------------------------------
显示出来就是:2008-05-05 05:03:00.0  怎么去掉后面的3个0 或小数点后面的1个0。

解决方案 »

  1.   

    .toString();
    然后用subString可以吗。
      

  2.   

    直接用String的substring不行?
    String tmp_str = rmatter.format(date);
    return tmp_str.substring(0, tmp_str.lastIndexOf("."));
      

  3.   

    new SimpleDateFormat("yyyy-MM-dd hh:mm", 
    locale); //改成:
    new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", 
    locale); //试试
      

  4.   

    我也觉得直接substring就可以了
      

  5.   

    我也遇到过这样的情况,想不到别的办法,用的就是substring,可以用的,
    String tmp_str = rmatter.format(date); 
    if((tmp_str!=null || tmp_str.length()!=0) && tmp_str.length()>19)
      tmp_str=tmp_str.substring(0,19);
      

  6.   

    "2008-05-05 05:03:00.0".substring(0,19)==2008-05-05 05:03:00