java SimpleDateFormat 年、月、日 时、分、秒

第一种:2022-03-03 22:40

Date current = new Date();
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm");
String time = sdf.format(current);
System.out.println(time);//2022-03-03 22:40

第二种:2022年03月03日 22时43分

SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分");
try {
	Date date = new Date();
	String dateStringParse = sdf.format(date);
	System.out.println(dateStringParse);//2022年03月03日 22时43分
} catch (Exception e) {
	e.printStackTrace();
}


版权声明:本文为tengyuxin原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。