扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

simpledateformat如何快速格式化当前时间

扬州沐宇科技
2024-06-19 14:10:02
simpledateformat

您可以使用以下代码来快速格式化当前时间:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date currentTime = new Date();
String formattedTime = sdf.format(currentTime);
System.out.println("Current time: " + formattedTime);

这段代码将当前时间格式化为"yyyy-MM-dd HH:mm:ss"的格式,并输出到控制台。您可以根据需要修改SimpleDateFormat中的格式化模式来获得不同的时间格式。

扫码添加客服微信