Thursday, 17 May 2018

How to set current date and next 7 days date on textview in android or JAVA

Public vois setTimeNextSevenDays() {
TextView mTitel1 = (TextView) findViewById(R.id.titel1);

String currentDate = Utils.getCurrentDateTime();
mTitel1.setText(Utils.getPastDate(1));
mTitel2.setText(Utils.getPastDate(2));
mTitel3.setText(Utils.getPastDate(3));
mTitel4.setText(Utils.getPastDate(4));
mTitel5.setText(Utils.getPastDate(5));
mTitel6.setText(Utils.getPastDate(6));
}


/*convert date into time am and pm 12 hour format * */public String convertDateToTime(String sDate) {
    String outputString = null;

    DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
    try {
        Date date = inputFormat.parse(sDate);
        DateFormat outputFormat = new SimpleDateFormat("hh:mm a");
        outputString = outputFormat.format(date).toLowerCase();
        return outputString;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return outputString;
}