public String time(){
//设置时间的格式
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
//得到本地时间
Date date = new Date(System.currentTimeMillis());
//返回数据
return dateFormat.format(date);
}
本文介绍了一种使用Java进行时间日期格式化的简单方法。通过创建SimpleDateFormat对象并指定格式字符串,可以将当前时间转换为特定格式的字符串。此方法适用于需要在应用程序中显示或记录时间的应用场景。
1282

被折叠的 条评论
为什么被折叠?



