Set Date/Time From String


The correct way to handle time and date is to use the Calendar object. The syntax is not immediately obvious, so here is an example:

// We have a string with a date:
String s = "27/09/1971";

// Format the string and put it in a Calendar object...
// NOTE: DateFormat.getDateTimeInstance() uses the current locale
Calendar c = Calendar.getInstance();