I have EditText
in my XML file:
this below code will help you
String string = editText.getText().toString();
DateFormat formatter = new SimpleDateFormat("hh:mm:ss a");
Date date = formatter.parse(string);
Try This:
EditText etExitHouret = (EditText) findViewById(R.id.etExitHour);
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); // Make sure user insert date into edittext in this format.
Date dateObject;
String date;
String time;
try {
String dob_var=(etExitHouret.getText().toString());
dateObject = formatter.parse(dob_var);
date = new SimpleDateFormat("dd/MM/yyyy").format(dateObject);
time = new SimpleDateFormat("h:mmaa").format(dateObject);
Toast.makeText(getBaseContext(), date + time, Toast.LENGTH_LONG).show();
}
catch (java.text.ParseException e) {
e.printStackTrace();
}
String str = editText.getText().toString();
DateFormat formatter = new SimpleDateFormat("hh:mm:ss a");
Date date = formatter.parse(str);