fork(9) download
  1. import java.text.*;
  2. import java.util.*;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. String myDate = "2-5-2012";
  7. String myTime = "20:43";
  8. String toParse = myDate + " " + myTime; // Results in "2-5-2012 20:43"
  9. try {
  10. SimpleDateFormat formatter = new SimpleDateFormat("d-M-yyyy hh:mm"); // I assume d-M, you may refer to M-d for month-day instead.
  11. Date date = formatter.parse(toParse); // You will need try/catch around this
  12. long millis = date.getTime();
  13. System.out.println(millis);
  14. } catch (ParseException pe) {
  15. pe.printStackTrace();
  16. }
  17. }
  18. }
Success #stdin #stdout 0.05s 246080KB
stdin
Standard input is empty
stdout
1335991380000