
//将某个时间已固定的格式转化成字符串
/*思路:
*
*/
import java.util.Date;
import java.text.SimpleDateFormat;
public class DateFormat {
public static void main(String[] args) {
// TODO Auto-generated method stub
Date now = new Date(); //得到显著的时间
System.out.println(date2FormatStr(now)); //打印显著时间的字符串格式
}
//得到固定字符串格式的方法
public static String date2FormatStr(Date date) {
//定义字符串格式
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str = sdf.format(date); //进行格式化,并得到字符串
return str; //返回结果
}
}点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号