.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。
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。
然后用subString可以吗。
String tmp_str = rmatter.format(date);
return tmp_str.substring(0, tmp_str.lastIndexOf("."));
locale); //改成:
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",
locale); //试试
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);