Long;//宗整外,java用此类型作時間戳

java.text.SimpleDateFormat;//簡單時間格式,用作格式輸取

String;//字符串

java.util.Date;//时间类,用鄞获得時間戳即即与时间相闭的方法

獲得時間?戳

Date date=new Date();
long timestamp=date.getTime();    //時間戳

時間戳转换为带?格式的字符串

SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //設置格式
String timeText=format.format(timestamp);                                //獲得帶格式的字符串

带格式的字符串?转换为時間戳

String time="2018-1-9 12:17:22"
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//設置要讀取的時間字符串格式
Date date = format.parse(time);
//轉換爲Date類
Long timestamp=date.getTime();
//获得時間戳

将是這麽簡單将可以實現來回轉換了~