I am creating a button in Android, minSdkVersion="8" and targetSdkVersion="17", for the user to select the date and time. With a onClick (selectDate) method as follows:
public void selectDate(View view) {
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getSupportFragmentManager(), "DatePicker");
}
public static void populateSetDate(int year, int month, int day) {
m_selectDateBtn.setText(month + "/" + day + "/" + year);
}
public static class DatePickerFragment extends DialogFragment implements
DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new DatePickerDialog(getActivity(), this, m_year, m_month,
m_day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
populateSetDate(year, month, day);
}
}
After looking at a few other questions on stackoverflow of how to parse the date text that will be stored in the button:
String to Date/Time object in Android
How can I recognize the Zulu time zone in Java DateUtils.parseDate?
Question: I am wondering what are the advantages and disadvantages of using SimpleDateFormat vs Joda Time? Or what other Date class would you recommend for what I want to do?
Joda Time does have some reason why to use Joda Time, but I do not know much about Date classes to know how true the statements are.
Advantages:
Example:
final Date curDateTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("hh:mma, MMM. dd");
String text = formatter.format(curDateTime);
Disadvantages:
Advantages:
Disadvantages:
For all date/time formatting I have needed, I am happy with SimpleDateFormat
and will continue using it. For my needs, there is no justified reason of which I am aware for switching to another library.