Date和String类型的转换(格式)

一、Date转String

SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
String str=sdf.format(new Date());//格式为yyyy-MM-dd

二、String转Date

SimpleDateFormat sdf1=new SimpleDateFormate("yyyy/MM/dd");
sdf1.parse(new String("2018/08/08"));//格式为Sun Sep 09 00:00:00 CST 2018

三、Data和Date之间的格式转换

Date d=new Date();
java.sql.Date date=new java.sql.Date(d.getTime());//转换成yyyy-MM-dd的格式

猜你喜欢

转载自blog.csdn.net/zcaixx/article/details/82658200
今日推荐