java 時間型別轉換
阿新 • • 發佈:2020-12-31
String 轉DateDate 轉String
import java.text.ParseException;
import java.text.SimpleDateFormat;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String s = "2020-12-30 11:05:34";
try {
Date date = format.parse(s);
log.info(date+"" );
} catch (ParseException e) {
e.printStackTrace();
}
Date date=new Date();
System.out.println(date);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String date1=sdf.format(date);
System.out.println(date1);