In my layout I have an EditText with InputType of time.
android:inputType="time"
How can I convert this to long?
I have a function that will convert from long to string using SimpleDateFormat, but I now need to do the opposite.
In my layout I have an EditText with InputType of time.
android:inputType="time"
How can I convert this to long?
I have a function that will convert from long to string using SimpleDateFormat, but I now need to do the opposite.
Something like this should do it:
EditText editText = (EditText) findViewById(R.id.edit_text);
String value = editText.getText().toString();
try {
DateFormat formatter = new SimpleDateFormat("hh:mm:ss");
Date date = (Date) formatter.parse(value);
long timeMilliSeconds = date.getTime();
}
catch (NumberFormatException e) {
System.out.println("Error getting value: " + e);
}