Showing posts with label timestamp. Show all posts
Showing posts with label timestamp. Show all posts

Java Date to SQL DateTime with timestamp

Date class is java.util.Date and while it is formatted as String (currentTime below), it can be inserted into DB field set as DATETIME.

                     // Change to string store in MySQL (DATETIME)  
                     Date dt = ugc.getCreate_time();  
                     java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
                     String currentTime = sdf.format(dt);  

Inserted record format: 2013-11-04 14:09:59