/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package datetest; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author admin */ public class DATETEST { public static void main(String[] args) { //将Date类型转成String类型,以String作为表名,保证表名唯一 Date now=new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); String tablename=dateFormat.format(now); System.out.println(tablename); //将String类型转成Date类型 String mydate="2014/2/2 17:02:12"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); try { Date date=sdf.parse(mydate); } catch (ParseException ex) { Logger.getLogger(DATETEST.class.getName()).log(Level.SEVERE, null, ex); } } }