Answers for "java+format sql time"

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

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language