Java时间转换demo
package com.ljquan.test.utils;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DatetimeFormat {
public static void main(String[] args) {
Date date = new Date();
long currentTimeMillis = System.currentTimeMillis();
Date date1 = new Date(currentTimeMillis);
System.out.println(date);
System.out.println(date.getTime());
String formatDateTime = "yyyy-MM-dd HH:mm:ss";
String formatDateTime1 = "yyyy-MM-dd";
String formatDateTime2 = "HH:mm:ss";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatDateTime);
System.out.println(simpleDateFormat.format(date));
System.out.println("===========");
System.out.println(simpleDateFormat.format(date1));
}
}
输出:
Sun May 01 16:40:24 CST 2022
1651394424743
2022-05-01 16:40:24
===========
2022-05-01 16:40:24
|