java date deal

package date.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateDealTest {

/**
* @param args
*/

public static void main(String[] args) {
try {
Class.forName(
"org.gjt.mm.mysql.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
String url =
"jdbc:mysql://localhost/bookstore?useUnicode=true&characterEncoding=gb2312";
String user =
"root";
String pswd =
"123456";
try {
String currDate =
"2007-12-30 08:24:37.0";
Timestamp ts=Timestamp.valueOf(currDate);
Connection conn = DriverManager.getConnection(url, user, pswd);
PreparedStatement prst = conn.prepareStatement(
"insert into test(id,addtime)values(2,?)");
//prst.setTimestamp(1, ts);
prst.setString(1, currDate);
prst.executeUpdate();
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery(
"select * from test");
while(rs.next()){

DateFormat  dft = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss ");
System.out.println(dft.format(rs.getTimestamp(
"ADDTIME")));

}
rs.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}

}

}
package date.util;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;

public class TestMain {

/**
* @param args
*/

public static void main(String[] args) {
System.currentTimeMillis();
Date d=new Date();
Calendar c = Calendar.getInstance();

String s =
"1970-12-30 08:24:37.0";
Timestamp ts=Timestamp.valueOf(s);
System.out.println(ts);
}

}

lunzi   2007-12-13 00:29:03 评论:0   阅读:362   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog