public static Date getDateFromString(String date, String fmt)
throws Exception {
if (date == null || date.trim().length() == 0)
return null;
SimpleDateFormat sdf = fmt == null ? new SimpleDateFormat(
DEFAULT_DATE_FORMAT) : new SimpleDateFormat(fmt);
return sdf.parse(date);
} 参数date为:2008-08-08 的话 fmt为:YYYY-MM-DD
你试下
throws Exception {
if (date == null || date.trim().length() == 0)
return null;
SimpleDateFormat sdf = fmt == null ? new SimpleDateFormat(
DEFAULT_DATE_FORMAT) : new SimpleDateFormat(fmt);
return sdf.parse(date);
} 参数date为:2008-08-08 的话 fmt为:YYYY-MM-DD
你试下
解决方案 »
- 想在网站内嵌一个发送短信的功能,请问大侠们,如何实现?
- java.lang.NullPointerException at org.apache.taglibs.standard.tlv.JstlBaseTLV.v
- 用纯JAVA实现页面显示报表,急求
- java的右击菜单,能提供一下这方面的资料吗?
- JSP如何传参数给ACTION
- 写程序的时候 突发的一个想法 结果发现自己的基础真差。。。能帮忙解释下 为什么会这样的
- struts 下数据源的配置问题
- 期待一个美好的开始-渴望学习J2EE
- 为什么jcreatepro2.5不能编译servlet的程序(难道是不支持吗)
- 部署ejb过程中weblogic报错!
- dom4j 能否获取某一个节点下的全部内容
- 谁给些java的程序设计题目啊
这是我自己常用的一些方法 public static long string2time(String date, String format) {
if (date == null) {
return 0;
}
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
Date dt = null; try {
dt = dateFormat.parse(date);
} catch (ParseException excpt) {
return 0;
}
return date2time(dt);
} public static String time2string(long time, String format) {
if (time == 0)
return "";
Date date = new Date(time);
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
return dateFormat.format(date);
} public static Date string2date(String date, String format) {
if (date == null) {
return null;
}
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
Date dt = null; try {
dt = dateFormat.parse(date);
} catch (ParseException excpt) {
return null;
}
return dt;
} public static String date2string(Date date, String format) {
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
return dateFormat.format(date);
} public static long date2time(Date date) {
Calendar cld = Calendar.getInstance();
cld.setTime(date);
return cld.getTimeInMillis();
}
如果就提论题,
得到后 date。 SimpleDateFormat f=new SimpleDateFormat("yyyy年-MM月-dd日"); 直接 f.format(date)就可以得到你想要的格式。
怎么还转换俩次。