In the application I am developing, I need to convert java.time.Instant object to java.sql.Timestamp. When I create Instant object lik
If you want the current timestamp why not use the following function, I have used this in various projects and works perfectly:
public static Timestamp getTimeStamp()
{
// Calendar information
Calendar calendar = Calendar.getInstance();
java.util.Date now = calendar.getTime();
Timestamp dbStamp = new Timestamp(now.getTime());
return dbStamp;
}
Example:
System.out.println( getTimeStamp() );
Output: 2017-03-13 15:01:34.027
EDIT
Using Java 8 LocalDateTime:
public static Timestamp getTimeStamp()
{
return Timestamp.valueOf(LocalDateTime.now());
}