0

In my project i am using the HorizontalPicker third party library for date selection. However i'm struggling to change the format of the DateTime variable when i display the value in a textview.

Output: enter image description here

How would i format this to something that is more easier for the user to read to something like "10-May-2020"

Code:

@Override
public void onDateSelected(@NonNull final DateTime dateSelected)
{
    displayDate.setText(dateSelected.toString());
}
Michael Hanson
  • 323
  • 4
  • 12

1 Answers1

1

Horizontal picker uses Joda Time for date and time. you can use DateTimeFormatter for foramt datetime. For more ref read How to format Joda-Time DateTime to only mm/dd/yyyy? answer.

@Override
public void onDateSelected(@NonNull final DateTime dateSelected)
{
      DateTimeFormatter dtfOut = DateTimeFormat.forPattern("dd-MMM-yyyy");
      // Printing the date
      System.out.println(dtfOut.print(dateSelected));
//    displayDate.setText(dateSelected.toString());
}
Upendra Shah
  • 2,218
  • 17
  • 27