温馨提示×

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

小樊
82
2024-06-19 14:10:02
栏目: 编程语言

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

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中的格式化模式来获得不同的时间格式。

0