fork(4) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.text.DateFormat;
  7. import java.text.SimpleDateFormat;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. Date startUserDate = new Date("02/20/2002");
  15. DateFormat df2 = new SimpleDateFormat("MM/dd/yyyy");
  16. System.out.println("Previous date: "+df2.format(startUserDate));
  17. DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
  18. String timeString = df.format(new Date()).substring(10); // 10 is the beginIndex of time here
  19.  
  20.  
  21. String startUserDateString = df2.format(startUserDate);
  22.  
  23. startUserDateString = startUserDateString+" "+timeString;
  24. // you will get this format "MM/dd/yyyy HH:mm:ss"
  25.  
  26. //then reparse the new date here
  27. startUserDate = df.parse(startUserDateString);
  28. System.out.println("Formatted date is: "+df.format(startUserDate));
  29. }
  30. }
Success #stdin #stdout 0.14s 321024KB
stdin
Standard input is empty
stdout
Previous date: 02/20/2002
Formatted date is: 02/20/2002 04:54:10