I have two function to calculate date and time.
public static String getFormattedDate(String time) {
long timeUnix = Long.parseLong(time);
Date myDate = new Date(timeUnix * 1000);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM d yy");
return simpleDateFormat.format(myDate);
}
public static String getFormattedTime(String time) {
long timeUnix = Long.parseLong(time);
Date myDate = new Date(timeUnix * 1000);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm:ss");
return simpleDateFormat.format(myDate);
}
I get the correct output from them which I need.
Jul 12 11(date function) and 12:09:45(time function)
How can I calculate days from this and how to set am/pm with this.
I am trying to set time with am/pm if it is today’s date and if it is older than show the day(mon,tue,wed etc.) and if it is more than week old than show “MMM d yy”.
For am/pm notation:
KK is hour in am/pm (0-11), while HH is hour in day (0-23)