-1

I have 2 inputs fields date and time

ex: 23/05/2014 as date and 5:30 as time (24 hour format)

how can i convert this 2 inputs into milliseconds in java

thanks

Raghuveer
  • 2,859
  • 7
  • 34
  • 66

2 Answers2

1

Maybe this helps you:

String dstr = ... // from date input field
String tstr = ... // from time input field

String pattern = "dd/MM/yyyy H:mm";
String dateTimeStr = dstr + " " + tstr;

SimpleDateFormat fmt = new SimpleDateFormat(pattern);
try {
    Date date = fmt.parse(dateTimeStr);
    long msecs = date.getTime();
} catch (ParseException ex) {
    // Handle parsing error here
}
DirkNM
  • 2,614
  • 15
  • 21
1
String givenDateString = "Tue Apr 23 16:08:28 GMT+05:30 2013"; 
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
try {
    Date mDate = sdf.parse(givenDateString);
    long timeInMilliseconds = mDate.getTime();
    System.out.println("Date in milli :: " + timeInMilliseconds);
} catch (ParseException e) {
            e.printStackTrace();
}
boycod3
  • 5,033
  • 11
  • 58
  • 87