Date d =newDate();SimpleDateFormat sbf =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");System.out.println(sbf.format(d));
或
System.out.println(newSimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(newDate()));2020-04-2814:23:05
Date date =newDate(System.currentTimeMillis());DateFormat dateFormat =newSimpleDateFormat("yyyy-MM-dd hh:mm:ss");String format = dateFormat.format(date);System.out.println(format);1588055609783-->2020-04-2802:33:29
年月日时间时分秒换成时间戳
leDateFormat simpleDateFormat =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date date = simpleDateFormat.parse("2020-04-28 02:33:29");long ts = date.getTime();System.out.println(ts);String res =String.valueOf(ts);// 转化为字符串System.out.println(res);1588012409000