1、用convert()转化函数:
String sqlst = "select convert(varchar(10),bookDate,126) as convertBookDate from roomBook where bookDate between '2007-4-10' and '2007-4-25'";
System.out.println(rs.getString("convertBookDate"));
2、利用SimpleDateFormat类:
先要输入两个java包:
import java.util.Date;
import java.text.SimpleDateFormat;
然后:
定义日期格式:SimpleDateFormat sdf = new SimpleDateFormat(yy-MM-dd);
sql语句为:String sqlStr = "select bookDate from roomBook where bookDate between '2007-4-10' and '2007-4-25'";
输出:
System.out.println(df.format(rs.getDate("bookDate"))); |
|