import java.text.SimpleDateFormat;
import java.util.Date;
public class Test {
public static void main(String[] args) {
Date date = new Date();// 获得当前的时间戳
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 定义格式
String nowTime = dateFormat.format(date);// 格式化时间
System.out.println(nowTime);
}
}
运行结果: