0
//The First Code
/*private String getDisplayTime(String datetime) {
    try {
        Date dt = sdf.parse(datetime);
        if (now.getYear()==dt.getYear() && now.getMonth()==dt.getMonth() && now.getDate()==dt.getDate()) {
            return df[1].format(dt);
        }
        return df[0].format(dt);
    } catch (ParseException e) {
        return datetime;
    }
}*/
//The second code
private String getDisplayTime(String dateTime) {
    try {
        //Date dt = sdf.parse(dateTime);
        Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));

        sdf.setCalendar(cal);
        sdf.parse(dateTime);
        if ( cal1.get(cal1.YEAR)==cal.get(cal.YEAR) && cal1.get(cal1.MONTH)==cal.get(cal.MONTH) && cal1.get(cal1.DATE)==cal.get(cal.DATE)) {
            return df[1].format(cal);           }
    } catch (ParseException e) {

    }
    return dateTime;
}

The Code above are two, but the first is the real one. But, the format has been deprecated so I can't use it. So, I did the second to test it, but I'm not getting the output I needed...Please Help me Out. Thank You.

1 Answers1

0

From Android Developers :

 String[] formats = new String[] {
   "yyyy-MM-dd",
   "yyyy-MM-dd HH:mm",
   "yyyy-MM-dd HH:mmZ",
   "yyyy-MM-dd HH:mm:ss.SSSZ",
   "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
 };
 for (String format : formats) {
   SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US);
   System.out.format("%30s %s\n", format, sdf.format(new Date(0)));
   sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
   System.out.format("%30s %s\n", format, sdf.format(new Date(0)));
 }

Try to search something next time before asking the question, there are a lot of examples of Date formating in Android. Or make your question more clear.

Yakiv Mospan
  • 8,174
  • 3
  • 31
  • 35