首页javajdbc_dataJava JDBC - 如何格式日期到/从字符串

Java JDBC - 如何格式日期到/从字符串

我们想知道如何格式日期到/从字符串。
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
  public static void main(String[] args) throws Exception {
    String someDate = "22/03/2015";
    SimpleDateFormat strToDate = new SimpleDateFormat("dd/MM/yyyy");
    Date currentDate = strToDate.parse(someDate);
    System.out.println("Date is :  " + currentDate);

    String dateFormat = "yyyy-MM-dd HH:mm:ss.SSS";
    SimpleDateFormat dateToStr = new SimpleDateFormat(dateFormat);
    String formattedDate = dateToStr.format(currentDate);
    System.out.println("Formated Date is : " + formattedDate);

  }
}