将"26/07/2021" 转换为Java LocalDate类对象,并打印,将上述对象转换为"dd-MM-yyyy" 并打印i.e. 27-07-2021
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main{
public static void main(String[] args){
Date date = new Date();
String strDateFormat = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
System.out.println(sdf.format(date));
}
}
LocalDate localDate = LocalDate.parse("26/07/2021", DateTimeFormatter.ofPattern("dd/MM/yyyy"));
System.out.println(localDate.format(DateTimeFormatter.ofPattern("dd-MM-yyyy")));
String time = "26/07/2021";
String[] sp = time.split("/");
LocalDate localDate = LocalDate.parse(sp[2]+"-"+sp[1]+"-"+sp[0]);
DateTimeFormatter f = DateTimeFormatter.ofPattern("dd-MM-yyyy");
System.out.println(localDate.format(f));
结果:
26-07-2021