Answers for "datetime sql to java format"

1

java sql date format

// This is an example to get the current date in java, with an sql date format

/*
I am using the imports below:
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
*/

DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");  
LocalDateTime now = LocalDateTime.now();
String dateTime = dtf.format(now);

// the dateTime variable is now ready to be inserted in mysql
// insert it as a String and it will be inserted in mysql as a dateTime
Posted by: Guest on April-27-2021
1

convert java date to sql date

public class MainClass {

  public static void main(String[] args) {
    java.util.Date utilDate = new java.util.Date();
    java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
    System.out.println("utilDate:" + utilDate);
    System.out.println("sqlDate:" + sqlDate);

  }

}
Posted by: Guest on August-27-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language