0

I have generate today date and separate day and month from the today date but its give ParseException.

Example : I have retrieve date 6 Aug 2018 11:14:02 am from separate day 6 and separate month 8.

try {
          String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
          SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy", Locale.US);
          Date date = format.parse(currentDateTimeString);


          SimpleDateFormat dayFormat = new SimpleDateFormat("dd");


          day = dayFormat.format(date);

          tvday.setText(day);

          SimpleDateFormat monthFormat = new SimpleDateFormat("MM");

          month = monthFormat.format(date);

          tvMonth.setText(month);
      } catch (ParseException e) {
          e.printStackTrace();
      }
rahul
  • 77
  • 1
  • 7

1 Answers1

1

Try this,

Calendar calendar;
calendar = Calendar.getInstance();
String YEAR=  calendar.get(Calendar.YEAR) 
String MONTH=  calendar.get(Calendar.MONTH) + 1) 
String DAY=  calendar.get(Calendar.DAY_OF_MONTH);
Gautam Surani
  • 1,011
  • 7
  • 20