当前位置:Gxlcms >
数据库问题 >
java.util.Date、java.sql.Date、java.sql.Time、java.sql.Timestamp区别和联系
java.util.Date、java.sql.Date、java.sql.Time、java.sql.Timestamp区别和联系
时间:2021-07-01 10:21:17
帮助过:10人阅读
demo;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TestData {
public static void main(String[] args)
throws ParseException {
Date d =
new Date(
new Date().getTime());
SimpleDateFormat sdf =
new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
String nowday1 =
"2015-5-12 10:30:12";
String nowday2 =
"2015-05-12 10:30:12";
Timestamp tt =
new Timestamp(System.currentTimeMillis());
System.out.println(sdf.format(d));
System.out.println(sdf.parse(nowday1));
System.out.println(sdf.format(tt));
System.out.println(tt.valueOf(nowday2));
System.out.println(d=tt);
System.out.println(
new Timestamp(d.getTime()));
}
}
/**
2015-05-12 10:44:15
Tue May 12 10:30:12 CST 2015
2015-05-12 10:44:15
2015-05-12 10:30:12.0
2015-05-12 10:44:15.108
2015-05-12 10:44:15.108
**/
java.util.Date、java.sql.Date、java.sql.Time、java.sql.Timestamp区别和联系
标签:jdk web开发