java日期格式化(util包下转成sql包下)

package test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Test {
     public static void main(String[] args) {
          Scanner input = new Scanner(System.in);
          System.out.println("请输入日期:");
          String mydate = input.next();
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
         
          try {
               java.sql.Date sqldate = new java.sql.Date(sdf.parse(mydate).getTime());
               System.out.println(sqldate);
          } catch (Exception e) {
               // TODO: handle exception
               e.printStackTrace();
          }
     }
}

posted @ 2016-03-11 13:47  刺风  阅读(699)  评论(0编辑  收藏  举报