public static void main(String[] args) {
int time = (int) System.currentTimeMillis();
String intDate = DateUtils.format(time, "yyyy-MM-dd HH:mm");
System.out.println(intDate);
int time11 = (int) (System.currentTimeMillis()/1000l);
String date11 = DateUtils.format((new Long(time11))*1000, "yyyy-MM-dd HH:mm");
System.out.println(date11);
long time1 = System.currentTimeMillis();
String date1 = DateUtils.format(time1, "yyyy-MM-dd HH:mm");
System.out.println(date1);
String time2 = "1637380527";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long longTime = new Long(new Long(time2)*1000);
Date date2 = new Date(longTime);
String dateTime = format.format(date2);
System.out.println(dateTime);
int times = (int) ((Timestamp.valueOf(dateTime ).getTime())/1000);
System.out.println(times);
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
long longTime1 = new Long(new Long(time2)*1000);
Date date3 = new Date(longTime1);
String dateTime1 = format1.format(date3);
System.out.println(dateTime1);
Date date = new Date(System.currentTimeMillis());
String dateFormat = "ss mm HH dd MM ? yyyy";
SimpleDateFormat sd = new SimpleDateFormat(dateFormat);
String formatTime = null;
if (date != null) {
formatTime = sd.format(date);
}
System.out.println(formatTime);
Date date5 = null;
try {
date5 = sd.parse(formatTime);
} catch (ParseException e) {
System.out.println("异常!");
}
System.out.println(date5);
}
结果:
1970-01-21 19:17
2021-11-29 09:59
2021-11-29 09:59
2021-11-20 11:55:27
1637380527
2021-11-20
23 59 09 29 11 ? 2021
Mon Nov 29 09:59:23 CST 2021