I have following method that I would like to make shorter or faster if nothing else. Please all comments are welcome:
Bellow method takes a date object, formates i
my understanding of the question is provide a simple method to produce output like the following:
Today at 20:00
Today at 20:30
Today at 21:00
Tomorrow at 06:45
Tomorrow at 07:00
Tomorrow at 08:15
the code below worked for me, but i am new to android and maybe others could point out if the code is not robust. in code below 'timeLong' is the time of my events in epoch time (milliseconds).
public String convertFromEpochTime (long timeLong) {
long timeNow = System.currentTimeMillis();
// get day in relative time
CharSequence timeDayRelative;
timeDayRelative = DateUtils.getRelativeTimeSpanString(timeLong, timeNow, DateUtils.DAY_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE);
// get hour in 24 hour time
Format hourFormatter = new SimpleDateFormat("HH:mm");
String timeHour = hourFormatter.format(timeLong);
// Log.d(DEBUG_TAG, "time of event: " + timeDayRelative + " at " + timeHour);
String timeDayHour = timeDayRelative + " at "+ timeHour;
return timeDayHour;
}