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

   2024-10-08 4520
核心提示:您可以使用以下代码来快速格式化当前时间:SimpleDateFormat sdf = new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);Date currentTim

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

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

 
举报打赏
 
更多>同类维修大全
推荐图文
推荐维修大全
点击排行

网站首页  |  关于我们  |  联系方式网站留言    |  赣ICP备2021007278号