我做了一个BBS系统,显示发帖和回帖时间时总是yyyy-mm-dd hh:mm:ss.0这样的格式 请问后面的“.0”是怎么来的?
在线等
在线等
解决方案 »
- 严重: Servlet.service() for servlet jsp threw exception
- Java读写Excel
- jspSmartUpload 组件上传茯取表单数据乱码,好久没解决???在线等!
- 一个简单的菜鸟问题。
- struts中表单相关问题,实在搞不懂.
- 针对用AJAX的网站,怎么用爬虫抓取
- myeclipse5.5中为什么没有Persistence Core Libraries?
- js加法运算(急)
- JSP有没有数据并发控制的能力?
- 求助!在document.getElementsByName不兼容的时候,该怎么办
- 请各位高手帮帮忙啊,帮我看一下
- 100分继续问标签的问题
public boolean insert(DB db) throws Exception {
String strSql;
ResultSet rs;
int iMaxId;
strSql = "Select max(id) From topic";
rs = db.OpenSql(strSql);
if (rs.next()) {
iMaxId = rs.getInt(1) + 1;
} else {
iMaxId = 1;
}
Calendar cal=Calendar.getInstance();
int year=cal.get(Calendar.YEAR);
int month=cal.get(Calendar.MONTH)+1;
int day=cal.get(Calendar.DATE);
int hour=cal.get(Calendar.HOUR_OF_DAY);
int minute=cal.get(Calendar.MINUTE);
int second=cal.get(Calendar.SECOND);
String submittime = year + "-" + month + "-" + day+" "+hour+":"+minute+":"+second;
strSql = "insert into topic values(" + iMaxId + ",'" + title + "','"
+ content + "','" + author + "','" + submittime + "'," + forumid
+ ")";
if (db.ExecSql(strSql) == 0) {
return false;
} else {
return true;
} }
也遇到同样问题使用了DataFormat来设置
strSql = "insert into topic values(" + iMaxId + ",'" + title + "','"
+ content + "','" + author + "',getDate()," + forumid
+ ")";前提条件是你的数据库支持 getDate()
* 返回格式为YYYY-MM-DD HH:MM:SS
* @param aDate
* java.util.Date
* @return
*/
public static final String getDateString(java.util.Date aDate) {
String ret = "";
Calendar c = Calendar.getInstance();
c.setTime(aDate); ret = c.get(Calendar.YEAR) + "-";
ret = ret + addZero((c.get(Calendar.MONTH) + 1) + "", 2) + "-";
ret = ret + addZero((c.get(Calendar.DAY_OF_MONTH)) + "", 2) + " ";
ret = ret + addZero((c.get(Calendar.HOUR_OF_DAY)) + "", 2) + ":";
ret = ret + addZero((c.get(Calendar.MINUTE)) + "", 2) + ":";
ret = ret + addZero((c.get(Calendar.SECOND)) + "", 2);
return ret;
}
DateVariable.substring(0,19);