how to format a datetime object to show date and time and milliseconds in java

Java
public String getCurrentTimeStamp() {
    return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
}
Source

Also in Java: