// 将日期格式转换成时间戳
1 public static void main(String[] args) throws Exception{ 2 String time = "2018-05-12 12:30:59"; 3 Date parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(time); 4 Long time1 = parse.getTime(); 5 System.out.println(time + " >> " + time1); 6 }
// 将时间戳转换成日期格式
1 public static void main(String[] args) { 2 Long time = 1527816283000L; 3 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 4 String time1 = sdf.format(new Date(time)); 5 System.out.println(time + " >> " + time1); 6 }