import java.sql.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class Demo1 {
public static void main(String[] args) throws ParseException {
/**
* 生成DateFormat類對象的固定格式
* */
DateFormat df = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss");
/**
* 獲取日期轉換為Unix時間戳
*/
long epoch = df.parse("2015-09-09 0:0:0").getTime();
System.out.println(epoch);
//1420777414000
/**
* 根據Unix時間戳得到時間
* */
Date d = new Date(epoch);
/**
* 轉換為日期
*/
String t = df.format(d);
System.out.println(t + " " + epoch);
}
}