java sql date format

Solutions on MaxInterview for java sql date format by the best coders in the world

showing results for - "java sql date format"
Gabriela
03 May 2017
1// This is an example to get the current date in java, with an sql date format
2
3/*
4I am using the imports below:
5import java.time.LocalDateTime
6import java.time.format.DateTimeFormatter
7*/
8
9DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");  
10LocalDateTime now = LocalDateTime.now();
11String dateTime = dtf.format(now);
12
13// the dateTime variable is now ready to be inserted in mysql
14// insert it as a String and it will be inserted in mysql as a dateTime