温馨提示×

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

小樊
114
2024-06-19 14:10:02
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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

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

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:深入理解Java:SimpleDateFormat安全的时间格式化

0