标签:int block cat tac amp ack new java logs
一、时间转换成时间戳
try {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = df.parse("2017-06-21 17:14:31"); Calendar cal = Calendar.getInstance(); cal.setTime(date); long timestamp = cal.getTimeInMillis(); System.out.println(timestamp); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); }
二、时间戳转换为时间
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Long time = new Long("1498036471000");
String d = format.format(time);
Date date1 = format.parse(d);
System.out.println("Format To String(Date):"+d);
System.out.println("Format To Date:"+date1);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
标签:int block cat tac amp ack new java logs
原文地址:http://www.cnblogs.com/MissRabbit/p/7060914.html