標籤:
/* * 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); } }}
JAVA擷取當前日期以及將字串轉成指定格式的日期