I'm working on a project in Android Studio 1.5.1. and I have TextView startDate = (TextView) findViewById(R.id.newevent_startdate);
now I need to use the value of startDate but as a type of java.sql.Date. how can I convert this?
I'm working on a project in Android Studio 1.5.1. and I have TextView startDate = (TextView) findViewById(R.id.newevent_startdate);
now I need to use the value of startDate but as a type of java.sql.Date. how can I convert this?
Suppose if you have a startDate in your TextView
with this format "yyyy-mm-dd" i.e 2016-01-26, then you can parse that to Date object using below code.
String startDateString = startDate.getText().toString() ; // where startDate is your TextView
SimpleDateFormat simpleDateFormat= new SimpleDateFormat("yyyy-MM-dd"); // same date format as your TextView supports
try {
Date date = simpleDateFormat.parse(startDateString); // parses the string date to get a date object
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}