当前位置:Gxlcms >
数据库问题 >
java.sql.Date java.util.Date String 的相互转换
java.sql.Date java.util.Date String 的相互转换
时间:2021-07-01 10:21:17
帮助过:11人阅读
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
-
- public class TransformDatet{
- public static void main(String[] args) {
-
- Date date = new Date();
- System.out.println("java.util.date :"+date.toString());
- java.sql.Date sqlDate = new java.sql.Date(date.getTime());
- System.out.println("java.sql.date :"+sqlDate.toString());
-
- Date date2 = new Date(sqlDate.getTime());
- System.out.println("java.util.date:"+date2);
-
-
- SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String formatUtilDate = sdf1.format(date);
- System.out.println("formatUtilDate:"+formatUtilDate);
-
- try {
- Date parseUtilDate = sdf1.parse(formatUtilDate);
- System.out.println("parseUtilDate:"+parseUtilDate);
- } catch (ParseException e) {
- e.printStackTrace();
- }
-
- SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
- String formatUtilDate2 = sdf2.format(date);
- System.out.println("formatUtilDate2:"+formatUtilDate2);
-
- try {
- Date parseUtilDate2 = sdf2.parse(formatUtilDate2);
- System.out.println("parseUtilDate2:"+parseUtilDate2);
- } catch (ParseException e) {
- e.printStackTrace();
- }
-
-
-
-
- String formatSqlDate = "2013-05-09";
- java.sql.Date valueOf = java.sql.Date.valueOf(formatSqlDate);
- System.out.println("valueOf:"+valueOf);
-
-
- java.sql.Date newSqlDate = new java.sql.Date(new Date().getTime());
- System.out.println("sqlDateToString:"+newSqlDate.toString());
-
- }
- }
java.sql.Date java.util.Date String 的相互转换
标签:tac format 需要 int 情况 href 之间 ati csdn