/** * Time of 24 hours display format/public class Formatdateutils {/**////////////////////////////////24 hours before
More than 24 hours three days (including three days) display a few days ago,//3 days above the display of the specific date, to the day.
Year displayed for more than one year, year not shown * @param * @return/public static string FormatDate (string para) {
Now the time Integer nowyear = Integer.parseint (DateTime.Now (). toString ("yyyy")); The time format datetimeformatter format = Datetimeformat.forpattern ("Yyyy-mm-dd HH:mm:ss.
S "); Time to parse DateTime paradate = DateTime.Parse (Para,format);//month day time seconds Integer parayear = Integer.parseint (P
Aradate.tostring ("yyyy"));//year String Paraday = paradate.tostring ("Yyyy-mm-dd"); DateTime nowdate = new DateTime (). now ();
Current Interval hours1 = new Interval (nowdate.minushours (1), nowdate);
Interval Hours24 = new Interval (nowdate.minushours), nowdate);
Interval day = new Interval (Nowdate.minusdays (4), nowdate); Interval years = new Interval (Nowdate.minusyears (1), nowdate);
if (Hours1.contains (paradate)) {//within one hour display minutes ago; Interval minute = new Interval (paradate, nowdate);
int res = Minute.toperiod (). getminutes ();
if (res = = 0 | | res = = 1) {return "just";
return res+ "Minutes ago";
Return "a few minutes ago";
else if (Hours24.contains (paradate)) {//24 hours before the display, Interval hours = new Interval (paradate, nowdate);
int res = Hours.toperiod (). GetHours ();
return res+ "hours ago";
Return "A few hours ago";
else if (Day.contains (paradate)) {//More than 24 hours three days (including three days) display a few days ago; Interval day = new Interval (paradate, nowdate);
int res = Day.toperiod (). GetDays ();
return res+ "days ago";
}else if (Parayear < nowyear) {return paraday;
}else {return paradate.tostring ("Mm-dd"); }
}
}