江西广告网

标题: Java入门:Date类型与String类型的转化 [打印本页]

作者: debaro    时间: 2009-2-9 09:48
标题: Java入门:Date类型与String类型的转化
import java.util.*; public class MyDate { public static Date dateFromString(String str) { if (str == null) { return null; } if (str.equalsIgnoreCase("")) { return null; } java.util.Date ret = null; try { java.sql.Date date = java.sql.Date.valueOf(str); ret = new Date(date.getTime()); } catch (Exception e) {} return ret; } public static String dateToString(Date date) { String ret = ""; if (date != null) { java.sql.Date sqldate = new java.sql.Date(date.getTime()); ret = sqldate.toString(); } return ret; } }




欢迎光临 江西广告网 (http://bbs.jxadw.com/) Powered by Discuz! X3.2