Date mydate=new Date();
auditrank.setSetdate(mydate);
此时数据库里的时间存储的是:2011-7-12 14:30:25
Date mydate=new Date();
SimpleDateFormat formatt=new SimpleDateFormat("MM/dd/yyyy");
String formatteddate=formatt.format(mydate);
java.text.SimpleDateFormat formatter=new java.text.SimpleDateFormat("MM/dd/yyyy");
java.util.Date date=formatter.parse(formatteddate);
auditrank.setSetdate(date);
此时数据库的时间存储的是:2011-7-12
两个时间之间的时长:
SimpleDateFormatmyFormatter=newSimpleDateFormat("yyyy-MM-dd");
java.util.Datedate=myFormatter.parse("2003-05-1");
java.util.Datemydate=myFormatter.parse("1899-12-30");
longday=(date.getTime()-mydate.getTime())/(24*60*60*1000);
本文详细解析了Java中日期格式的使用方法及其与数据库存储的关联,通过实例展示了如何将不同格式的日期字符串转换为数据库可识别的日期,并讨论了两者之间的时长计算。

被折叠的 条评论
为什么被折叠?



